uni-app自定义动态底部导航tabbar|仿微信tabbar导航栏,支持当前第几个选中、自定义背景、图片/图标、字体颜色
uni-app原生导航tabBar功能也挺好,不过有时为了知足多样化的项目需求,如:背景色渐变、字体图标,一些特殊图标凸显效果,这时候就只能自定义tabbar来实现功能了。
vue
以下图:分别在H5端、小程序、APP端实现的自定义tabbar效果小程序
<block v-for="(item,index) in tabList" :key="index">
<view class="navigator" :class="currentTabIndex == index ? 'on' : ''" @tap="switchTab(index)">
<view class="icon">
<text class="iconfont" :class="item.icon" :style="[currentTabIndex == index ? {'color': tintColor} : {'color': color}]"></text>
<text v-if="item.badge" class="uni_badge">{{item.badge}}</text>
<text v-if="item.badgeDot" class="uni_badge uni_badge_dot"></text>
</view>
<view class="text" :style="[currentTabIndex == index ? {'color': tintColor} : {'color': color}]">{{item.text}}</view>
</view>
</block>
复制代码
<script>
export default {
data() {
return {
tabList: [
{
icon: 'icon-emotion',
text: 'tab01',
badge: 1
},
{
icon: 'icon-qianbao',
text: 'tab02',
},
{
icon: 'icon-choose01',
text: 'tab03',
badgeDot: true
}
],
currentTabIndex: this.current
}
},
props: {
current: { type: [Number, String], default: 0 },
backgroundColor: { type: String, default: '#fbfbfb' },
color: { type: String, default: '#999' },
tintColor: { type: String, default: '#42b983' }
},
methods: {
switchTab(index){
this.currentTabIndex = index
this.$emit('click', index)
}
},
}
</script>
复制代码
import tabBar from './components/tabbar.vue'
Vue.component('tab-bar', tabBar)
复制代码
此时的tab-bar已是全局组件了,只需在须要的视图页面引用便可bash
<tab-bar :current="currentTabIndex" backgroundColor="#fbfbfb" color="#999" tintColor="#42b983" @click="tabClick"></tab-bar>
复制代码
<tab-bar :current="2" backgroundColor="#1a4065" color="#c3daf1" tintColor="#02f32b" @click="tabClick"></tab-bar>
复制代码
另外还支持点击tabbar选项返回索引值微信
data() {
return {
...
currentTabIndex: 1
}
},
methods: {
tabClick(index){
console.log('返回tabBar索引:' + index)
this.currentTabIndex = index
},
...
},
复制代码
最后附上uni-app自定义导航栏,但愿能喜欢😎😎~~app
uniApp自定义顶部导航:juejin.im/post/5d806b…post