前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布

TabBar

作者头像
Qwe7
发布2022-05-31 08:31:15
3550
发布2022-05-31 08:31:15
举报
文章被收录于专栏:网络收集网络收集

四、案例

1、TabBar

TabBar.vue

代码语言:javascript
复制
<template>
  <div class="tab-bar">     
      <slot></slot>
  </div>
</template>

<script>
export default {
  name: 'TabBar',
  data() { 
    return {
    }
  }
 }
</script>

<style scoped>
.tab-bar{
  display: flex;
  background-color: #f6f6f6;
  
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;

  box-shadow: 0 -3px 1px rgba(100, 100, 100, 0.1);
}

</style>

TabBarItem.vue

代码语言:javascript
复制
<template>
  <div class="tab-bar-item" @click="itemClick()">
      <div v-if = "!isActive"><slot name = "item-icon"></slot></div>
      <div v-else><slot name = "item-icon-active"></slot></div>
      
      <div :style="activeStyle"><slot name = "item-text"></slot></div>
      
    <!-- <img src = "../../assets/img/tabbar/home.svg" alt="">
    <div>首页</div> -->
  </div>
</template>

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

<style scoped>
.tab-bar-item{
  flex: 1;
  text-align: center;
  height: 49px;
}
.tab-bar-item img{
    width:24px;
    height: 24px;
    margin-top: 3px;
    vertical-align: middle;
}
.active{
    color: blueviolet;
}
</style>

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档