<cover-view class="tab-bar">
<cover-view class="tab-bar-border"></cover-view>
<cover-view wx:for="{{list}}" wx:key="index" class="tab-bar-item" data-path="{{item.pagePath}}" data-index="{{index}}" bindtap="tabChange">
<cover-image src="{{tabbarIndex === index ? item.selectedIconPath : item.iconPath}}"></cover-image>
<cover-view style="color: {{tabbarIndex === index ? selectedColor : color}}">{{item.text}}</cover-view>
</cover-view>
</cover-view>
Component({
properties: {
list: {
type: Array,
value: []
},
selectedColor:{
type: String,
value:''
},
color:{
type: String,
value:''
},
},
data: {
tabbarIndex: 0//默认显示第一个tab元素
},
methods: {
//组件的点击事件
tabChange(e) {
//获取到底部栏元素的下标
let index = e.currentTarget.dataset.index;
this.setData({
tabbarIndex:index,
})
//triggerEvent获取组件的事件
//onMyEvent 页面传过来的点击事件名称
this.triggerEvent('onMyEvent',{
tabbarIndex:index,
})
},
}
})
{
"navigationBarTitleText": "测试",
"usingComponents": {
"mp-tabbar": "../components/tabBar/index"
}
}
<view wx:if="{{tabbarIndex == 0}}">111111</view>
<view wx:if="{{tabbarIndex == 1}}">222222</view>
<view wx:if="{{tabbarIndex == 2}}">333333</view>
<mp-tabbar list="{{list}}" id='tabComponent' bind:onMyEvent="switchTab"></mp-tabbar>
//获取组件传递出来的数据
switchTab:function(e){
let index = e.detail.tabbarIndex;
this.setData({
tabbarIndex:index
})
console.log(e.detail.tabbarIndex)
}
本文地址:https://blog.csdn.net/gyueh/article/details/107484540
如对本文有疑问, 点击进行留言回复!!
同事牛逼啊,写了个隐藏 bug,我排查了 3 天才解决问题!
【JavaScript笔记(一)】万丈高楼平地起 - 基本概念篇
轻松解决 org.apache.taglibs.standard.tlv.JstlCoreTLV 困惑
网友评论