<template>
  <div>
    <van-tabbar fixed route v-model="active" @change="handleChange">
      <van-tabbar-item v-for="(item, index) in tabbars" :to="item.to" :key="index">
        {{ item.title }}
        <template #icon="props">
          <img :src="props.active ? item.icon.active : item.icon.inactive" />
        </template>
      </van-tabbar-item>
    </van-tabbar>
  </div>
</template>
<script>
export default {
  name: 'TabBar',
  props: {
    defaultActive: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      active: this.defaultActive,
      tabbars: [
        {
          title: '成长',
          to: {
            name: 'Development'
          },
          icon: {
            active: require('../assets/com-imges/55_41.png'),
            inactive: require('../assets/com-imges/55_17.png')
          }
        },
        {
          title: '今日',
          to: {
            name: 'Today'
          },
          icon: {
            active: require('../assets/com-imges/55_36.png'),
            inactive: require('../assets/com-imges/55_20.png')
          }
        },
        {
          title: '洞悉',
          to: {
            name: 'Insight'
          },
          icon: {
            active: require('../assets/com-imges/55_38.png'),
            inactive: require('../assets/com-imges/55_22.png')
          }
        },
        {
          title: '优化',
          to: {
            name: 'Optimize'
          },
          icon: {
            active: require('../assets/com-imges/55_44.png'),
            inactive: require('../assets/com-imges/55_25.png')
          }
        },
        {
          title: '我的',
          to: {
            name: 'Myself'
          },
          icon: {
            active: require('../assets/com-imges/55_33.png'),
            inactive: require('../assets/com-imges/55_14.png')
          }
        }
      ]
    };
  },
  methods: {
    handleChange(value) {
      this.$emit('change', value);
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
