实现功能:切换1级tab时,2级tab恢复默认第一个选中。

误区:看了官方文档,误以为直接在1级tab的change事件中更改2级tab的current属性就可以实现,但是这个值并不是双向绑定的,2级tab同样需要在change事件中手动修改选中下标

解决:2级tab也需要在change事件中修改current

// 2级tab
<uv-tabs
	:list="labelList"
	:current="activeIndex"
	:scrollable="labelList.length > 3"
	lineColor="#409EFF"
	:activeStyle="{
		color: '#253858',
		fontWeight: '610'
	}"
	:inactiveStyle="{
		color: '#505F79',
		fontWeight: '400'
	}"
	:itemStyle="{ padding: '0 32rpx', height: '88rpx' }"
	@change="changeTab2"
></uv-tabs>


data(){
   return{
        activeIndex: 0,
    }

}

// 1级tab
changeTab(e) {
     uni.$uv.throttle(async () => {
          this.activeIndex = 0; // 下级tab重置为第一个
          ......

     }, 200);
},

// 2级tab
changeTab2(item) {
    this.activeIndex = item.index;
	......
}

更多推荐