TabBar.vue 890 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <template>
  2. <div>
  3. <van-tabbar fixed route v-model="active" @change="handleChange">
  4. <van-tabbar-item v-for="(item, index) in data" :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. methods: {
  31. handleChange(value) {
  32. this.$emit('change', value)
  33. }
  34. }
  35. }
  36. </script>
  37. <!-- Add "scoped" attribute to limit CSS to this component only -->
  38. <style scoped>
  39. h3 {
  40. margin: 40px 0 0;
  41. }
  42. ul {
  43. list-style-type: none;
  44. padding: 0;
  45. }
  46. li {
  47. display: inline-block;
  48. margin: 0 10px;
  49. }
  50. a {
  51. color: #42b983;
  52. }
  53. </style>