当前位置:   article > 正文

前端Vue实现tabbar组件

tabbar

tabbar组件的实现

TabBar.vue组件

tabbar组件只需要在内写一个插槽即可,将来往里面放tabbaritem即可

<template>
    <div id='tab-bar'>
      <slot></slot>
    </div>
</template>


<script>
export default {
  name: 'TabBar',
  props:{

  },
  data () {
    return {
    }
  }
}
</script>

<style scoped>
  #tab-bar {
    display: flex;
    background-color: #f6f6f6;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    box-shadow: 0px -1px 1px rgba(100, 100, 100, 0.08)
  }

</style>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

TabBarItem组件

TabBarItem组件主要为TabBar内部的子组件将来项目需要放多少个就可以放多少个,并且点击的时候将会跳转到对应的路由当中

<template>
  <div  class="tab-bar-item" @click="itemClick">
    <template v-if="!isActive"><slot name="item-icon"></slot></template>
    <template v-else><slot name="item-icon-active"></slot></template>
    <div :style="this.activeStyle"><slot name="item-text"></slot></div>
  </div>
</template>


<script>
export default {
  name: 'TabBarItem',
  props: {
    path: String,
    activeColor: {
      type: String,
      default: 'red'
    }
  },
  data () {
    return {
    }
  },
  computed: {
    isActive() {
      return this.$route.path.indexOf(this.path) != -1;
    },
    activeStyle() {
      return this.isActive ? {color: this.activeColor} : {};
    },
  },
  methods:{
    itemClick() {
      this.$router.push(this.path);
    }
  }
}
</script>

<style scoped>
  .tab-bar-item {
    flex: 1;
    height: 49px;
    text-align: center;
    font-size: 14px;
  }
  .tab-bar-item img {
    width: 24px;
    height: 24px;
    margin-top: 3px;
    margin-bottom: 2px;
    vertical-align: middle;
  }
</style>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号