vue组件tabbar使用方法详解

在做项目时,实现tab页时有tabbar,其他页面没有,则可以如下操作:

  • 在App.vue中
<template>
  <div id="app">
     <transition :name="viewTransition">
      <router-view class="router-view" />
    </transition>
     <Tabbar v-if="tabbarShow"></Tabbar>
  </div>
</template>

<script>
import Tabbar from '@/pages/common/tabbar.vue'
export default {
  name: 'App',
  components: {
    Tabbar
  },
  // 监听,当路由发生变化的时候执行
  watch:{
    $route(to,from){
      //判断是否显示tabbar
      if(to.path == '/' || to.path == '/index' || to.path == '/mine'){
        this.$store.commit('updateTabbarShow',true);
      }else{
        this.$store.commit('updateTabbarShow',false);
      }

    }
 },
  computed: {
    tabbarShow(){
      return this.$store.getters.getTabbarShow
    }
  },
}
</script>

<style lang="less">

</style>

  • tabbar.vue文件为
<template>
  <div class="tabbar">
      <tabbar>
        <tabbar-item selected link="/index">
          <img slot="icon" src="../../assets/images/icon.png">
          <img slot="icon-active" src="../../assets/images/active-icon.png">
          <span slot="label">首页</span>
        </tabbar-item>
        <tabbar-item>
          <img slot="icon" src="../../assets/images/icon.png">
          <img slot="icon-active" src="../../assets/images/active-icon.png">
          <span slot="label">开庄</span>
        </tabbar-item>
        <tabbar-item >
          <img slot="icon" src="../../assets/images/icon.png">
          <img slot="icon-active" src="../../assets/images/active-icon.png">
          <span slot="label">我的投注</span>
        </tabbar-item>
        <tabbar-item link="/mine">
          <img slot="icon" src="../../assets/images/icon.png">
          <img slot="icon-active" src="../../assets/images/active-icon.png">
          <span slot="label">我的</span>
        </tabbar-item>
      </tabbar>
  </div>
</template>

<script>
import { Tabbar, TabbarItem } from 'vux'
export default {
  components: {
    Tabbar,
    TabbarItem
  },
  data(){
    return {
    }
  },
  methods:{},
  created(){},
  mounted(){}
}
</script>
<style scoped>
</style>
  • store文件夹中的index.js
import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    tabbarShow:true
  },
  getters:{
    getTabbarShow(state){
        return state.tabbarShow
    }
  },
  mutations: {
    updateTabbarShow(state, payload){
      state.tabbarShow = payload
    }
  },
  actions: {}
});

  • 效果如下:


    效果图.jpg
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 基于Vue的组件库 https://github.com/ElemeFE/element" element 饿了...
    _执着执着再执着阅读 32,882评论 4 230
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,303评论 4 61
  • 在重庆,人们要么见到夏天烈日当空的日子,要么是绵绵不断的细雨下个不停的日子,。。。。最多了时候就是天空阴沉沉,不出...
    牛德华12345阅读 344评论 0 0
  • “人生近看是悲剧,远看是喜剧。”是人称喜剧之王的查理·卓别林所演绎的,这句话并不只是简单的字面意思,更是平民百姓的...
    钱莱爱读书阅读 645评论 1 4
  • 原来还是故作平静,自以为时间够长了,足够去忘记那些事情,那个人。那就是自己演技够高,再次见面,再次相处,一切都风轻...
    右颜AND右艺阅读 368评论 0 0