自定义底部tabbar点击某一个后没有显示相应状态
根据官方demo写的自定义底部tabbar,当在点击其中一个的时候没切换相应的状态,如图默认状态 [图片] 当点击关注的时候路径变了,但是没有显示没有切换到关注 [图片] 代码如下: [代码]<[代码][代码]cover-view[代码] [代码]class[代码][代码]=[代码][代码]"tab-bar"[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]cover-view[代码] [代码]class[代码][代码]=[代码][代码]"tab-bar-border"[代码] [代码]style[代码][代码]=[代码][代码]"background-color:{{borderColor}}"[代码][代码]></[代码][代码]cover-view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]cover-view[代码] [代码]class[代码][代码]=[代码][代码]"progress"[代码] [代码]style[代码][代码]=[代码][代码]"width:{{progress}};background-color:{{progressColor}}"[代码][代码]></[代码][代码]cover-view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]block[代码] [代码]wx:for[代码][代码]=[代码][代码]"{{list}}"[代码] [代码]wx:key[代码][代码]=[代码][代码]"index"[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]cover-view[代码] [代码]class[代码][代码]=[代码][代码]"tab-bar-item"[代码] [代码]data-path[代码][代码]=[代码][代码]"{{item.pagePath}}"[代码] [代码]data-index[代码][代码]=[代码][代码]"{{index}}"[代码] [代码]bindtap[代码][代码]=[代码][代码]"switchTab"[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]cover-view[代码] [代码]style[代码][代码]=[代码][代码]"color: {{selected == index ? selectedColor : color}}"[代码] [代码]wx:if[代码][代码]=[代码][代码]"{{item.text}}"[代码][代码]>{{item.text}}</[代码][代码]cover-view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]cover-image[代码] [代码]src[代码][代码]=[代码][代码]"{{selected == index ? item.selectedIconPath : item.iconPath}}"[代码] [代码]class[代码][代码]=[代码][代码]"single-img"[代码] [代码]wx:else></[代码][代码]cover-image[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]cover-view[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]block[代码][代码]>[代码][代码]</[代码][代码]cover-view[代码][代码]>[代码][代码]Component({[代码][代码] [代码][代码]data: {[代码][代码] [代码][代码]selected: 0,[代码][代码] [代码][代码]color: [代码][代码]"#7A7E83"[代码][代码],[代码][代码] [代码][代码]selectedColor: [代码][代码]"#fff"[代码][代码],[代码][代码] [代码][代码]borderColor: [代码][代码]"rgba(0, 0, 0, 0.33)"[代码][代码],[代码][代码] [代码][代码]progress: [代码][代码]'80%'[代码][代码],[代码][代码] [代码][代码]progressColor: [代码][代码]"#f40"[代码][代码],[代码][代码] [代码][代码]list: [{[代码][代码] [代码][代码]pagePath: [代码][代码]"/index/index/index"[代码][代码],[代码][代码] [代码][代码]iconPath: [代码][代码]"/image/icon_component.png"[代码][代码],[代码][代码] [代码][代码]selectedIconPath: [代码][代码]"/image/icon_component_HL.png"[代码][代码],[代码][代码] [代码][代码]text: [代码][代码]"首页"[代码][代码] [代码][代码]}, {[代码][代码] [代码][代码]pagePath: [代码][代码]"/index/follow/follow"[代码][代码],[代码][代码] [代码][代码]iconPath: [代码][代码]"/image/icon_API.png"[代码][代码],[代码][代码] [代码][代码]selectedIconPath: [代码][代码]"/image/icon_API_HL.png"[代码][代码],[代码][代码] [代码][代码]text: [代码][代码]"关注"[代码][代码] [代码][代码]}, {[代码][代码] [代码][代码]pagePath: [代码][代码]"/index/record/record"[代码][代码],[代码][代码] [代码][代码]iconPath: [代码][代码]"/image/icon_API.png"[代码][代码],[代码][代码] [代码][代码]selectedIconPath: [代码][代码]"/image/icon_API_HL.png"[代码][代码],[代码][代码] [代码][代码]text: [代码][代码]""[代码][代码] [代码][代码]}][代码][代码] [代码][代码]},[代码][代码] [代码][代码]attached() {},[代码][代码] [代码][代码]methods: {[代码][代码] [代码][代码]switchTab(e) {[代码][代码] [代码][代码]const data = e.currentTarget.dataset[代码][代码] [代码][代码]const url = data.path[代码][代码] [代码][代码]wx.switchTab({[代码][代码] [代码][代码]url[代码][代码] [代码][代码]})[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]selected: data.index[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码]})[代码]