vue 做的tabBar组件

效果如下

调用

<tabbar :selected='selected'></tabbar>
组件
<template>
  <div class='tabbar'>
    <ul>
      <li @click="go(item.path)"
          :class="{active:message==item.path}"
          v-for="(item,index) in atabs">
        <img :src="message==item.path?item.icon_active:item.icon"
             alt="">
        {{item.title}}
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  props: {
    selected: String,
  },
  name: 'tabbar',
  data () {
    return {
      message: this.selected,
      atabs: [
        { title: '首页', path: 'index', icon: require('@/assets/images/index.png'), icon_active: require('@/assets/images/index-active.png') },
        { title: '附近门店', path: 'storeLists', icon: require('@/assets/images/storeLists.png'), icon_active: require('@/assets/images/storeLists-active.png') },
        { title: '我的', path: 'gettheOrder', icon: require('@/assets/images/gettheOrder.png'), icon_active: require('@/assets/images/gettheOrder-active.png') }
      ]
    }
  },
  methods: {
    go (url) {
      this.$router.push(`/${url}`)
    }
  },
}
</script>
<style lang="less" scoped>
.tabbar {
  position: fixed;
  left: 0;
  bottom: 0;
   100%;
  height: 0.45rem;
  ul {
     100%;
    height: 100%;
    display: flex;
    justify-content: space-around;
    background-color: #fff;
    li {
      display: flex;
      flex-direction: column;
      justify-content: center;
       100%;
      text-align: center;
      // padding: 7px 0;
      border-top: 1px solid #eaeaea;
      font-size: 0.1rem;
      img {
         0.2rem;
        height: 0.2rem;
        margin: 5px auto 0px;
      }
      &.active {
        color: #ff5621;
        font-weight: bold;
      }
    }
  }
}
</style>

  

原文地址:https://www.cnblogs.com/reaf/p/11180634.html