// 自定义tabba --> rindex.wxml <cover-view class="tab-bar" wx:if="{{showTabBar}}"> <cover-view class="tab-bar-border"></cover-view> <cover-view wx:for="{{isClientVersion?clientList:shopList}}" wx:key="index" class="tab-bar-item" data-path="{{item.pagePath}}" data-selectedPath="{{item.selectedIconPath}}" data-index="{{index}}" bindtap="switchTab" > <cover-image class="cover-image" src="{{selected === index ? item.selectedIconPath : item.iconPath}}"> </cover-image> <cover-view class="cover-view" style="color: {{selected === index ? selectedColor : color}}"> {{item.text}} </cover-view> </cover-view> </cover-view> // index.js var app = getApp(); Component({ data: { showTabBar:true, selected: 0, color: "#7A7E83", selectedColor: "#3cc51f", isClientVersion:app.globalData.isClientVersion, clientList: [{ pagePath: "/pages/index/index", iconPath: "/assets/tabBar/order-nor@2x.png", selectedIconPath: "/assets/tabBar/order-press@2x.png", text: "预约" }, { pagePath: "/pages/message/message", iconPath: "/assets/tabBar/my-nor@2x.png", selectedIconPath: "/assets/tabBar/my-press@2x.png", text: "我的" }], shopList: [{ pagePath: "/pages/managementServiceList/managementServiceList", iconPath: "/assets/tabBar/my-nor@2x.png", selectedIconPath: "/assets/tabBar/my-press@2x.png", text: "服务列表" }, { pagePath: "/pages/message/message", iconPath: "/assets/tabBar/my-nor@2x.png", selectedIconPath: "/assets/tabBar/my-press@2x.png", text: "我的" }], realList:[] }, // 组件生命周期 lifetimes:{ attached(){ this.setData({ isClientVersion:app.globalData.isClientVersion, }) } }, methods: { switchTab(e) { const data = e.currentTarget.dataset const url = data.path wx.switchTab({url}) } } }) // ‘我的’相关代码 onShow(){ if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ selected: 1 // 根据tab的索引值设置 }) } // ‘预约页面’相关代码 onShow(){ if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ selected: 0 // 根据tab的索引值设置 }) } // ‘服务列表’相关代码 onShow(){ if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ selected: 0 // 根据tab的索引值设置 }) }
根据身份不同更换tabbar列表。自定义tabBar更换list,在真机上总是显示更换前的数据?在模拟器上点击切换商家,tabbar变化[图片] 2. [图片]如图所示,变为服务列表-我的 3.点击服务列表,跳转到服务列表页面[图片] 以上全部正常。 但是,在真机上时,第一、二步正常,第三步时自动切换tabbar为更改之前的数据。[图片]点击服务列表之后,变为预约了,这是怎么搞得啊?实在不知道怎么解决了[图片]有没有人遇到过相似的问题啊?
2023-01-03