TabBar.vue 920 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <div>
  3. <van-tabbar route v-model="active" @change="handleChange">
  4. <van-tabbar-item v-for="(item, index) in data" :dot="item.dot" :to="item.to" :icon="item.icon" :key="index">
  5. {{ item.title }}
  6. </van-tabbar-item>
  7. </van-tabbar>
  8. </div>
  9. </template>
  10. <script>
  11. export default {
  12. name: 'TabBar',
  13. props: {
  14. defaultActive: {
  15. type: Number,
  16. default: 0
  17. },
  18. data: {
  19. type: Array,
  20. default: () => {
  21. return []
  22. }
  23. }
  24. },
  25. data() {
  26. return {
  27. active: this.defaultActive
  28. }
  29. },
  30. mounted() {
  31. },
  32. methods: {
  33. handleChange(value) {
  34. this.$emit('change', value)
  35. }
  36. }
  37. }
  38. </script>
  39. <!-- Add "scoped" attribute to limit CSS to this component only -->
  40. <style scoped>
  41. h3 {
  42. margin: 40px 0 0;
  43. }
  44. ul {
  45. list-style-type: none;
  46. padding: 0;
  47. }
  48. li {
  49. display: inline-block;
  50. margin: 0 10px;
  51. }
  52. a {
  53. color: #42b983;
  54. }
  55. </style>