TabBar.vue 1.41 KB
<template>
  <van-tabbar
    route
    @change="change"
    v-model="value"
    :border="false"
    :safe-area-inset-bottom="true"
  >
    <template v-for="(i,index) in data">
      <van-tabbar-item
        :key="index"
        replace
        :to="`/${i.name}`"
        :name="i.name"
      >
        <template #icon="props">
          <img :src="props.active ? i.active : i.inactive" />
        </template>
        <div class="text">{{i.title}}</div>
      </van-tabbar-item>
    </template>
  </van-tabbar>
</template>
<script>
export default {
  name: 'TabBar',
  props: {
    routerName: {
      type: String,
      default: 'home'
    },
    parent: String,
    data: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  data () {
    return {
      value: this.routerName
    }
  },
  methods: {
    change (value) {
      this.$emit('change', value)
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang='scss'>
.van-tabbar {
  background: #fff;
  // box-shadow: 0px -2px 4px 0px rgba(0, 0, 0, 0.04);
  overflow: hidden;
  z-index: 3;
  border-radius: 16px 16px 0 0;
 
  .van-tabbar-item {
    font-size: 12px;
    position: relative;
    color: #B1B1B3;
    .text{
      line-height: 17px;
    }
  }
  .van-tabbar-item--active {
    color: var(--themeColor);
  }
  .van-tabbar-item__icon img {
    width: 24px;
    height: 25px;
  }
}
</style>