自定义tabBar数据我是放在utils的tabBar.js文件中:
export const tabBar = {
user: [
{
pagePath: "../index/index",
text: "首页",
iconPath: "../icons/shouye.png",
selectedIconPath: "../icons/shouye-sele.png"
},
{
pagePath: "../category/index",
text: "分类",
iconPath: "../icons/fenlei.png",
selectedIconPath: "../icons/fenlei-sele.png"
},
{
pagePath: "../cart/index",
text: "购物车",
iconPath: "../icons/gouwuche.png",
selectedIconPath: "../icons/gouwuche-sele.png"
},
{
pagePath: "../user/index",
text: "我的",
iconPath: "../icons/wode.png",
selectedIconPath: "../icons/wode-sele.png"
}
],
cut: [
{
pagePath: "../order/index",
text: "订单",
iconPath: "../icons/order.png",
selectedIconPath: "../icons/order-sele.png"
},
{
pagePath: "../user/index",
text: "我的",
iconPath: "../icons/wode.png",
selectedIconPath: "../icons/wode-sele.png"
}
]
}
引入utils/tabBar.js文件,每一次点击切换登录端从引入的文件中拿到对应的数据,调用getTabBar()改变custom-tab-bar的数据
getStorageSync(){
wx.setStorageSync('actype','cut')
this.tabBarFun()
}
tabBarFun() {
const actype = wx.getStorageSync('actype')
let tabBars = []
if(actype == 'user') {
tabBars = tabBar.user
} else if(actype == 'cut') {
tabBars = tabBar.cut
} else if(actype == 'admin') {
tabBars = tabBar.admin
} else {
tabBars = tabBar.user
}
wx.setStorageSync('tabBar', tabBars)
const tab = this.getTabBar()
tab.setData({
tabBar:tabBars
})
},
然后遇到了问题,点击切换登录端后,虽然数据都会改变但是会有两个问题:
1.每一次刷新,小程序会自启动首页,只有点击修改数据后索引为0的ta才会正常 (这个问题已经解决,我是在app.js判断每次在点击切换登录端时储存的一个值,来跳转到对应的页面,问题是解决了但是这方法不好使)
2.每一次点击完切换登录端后,数据会错乱,只有刷新了才会正常
这个是没点切换之前的用户tabBar
这是点了切换之后的配送tabBar
在不刷新的情况下,点击订单tabBar,就会变成这样
刷新之后,就正常了
大锅们,请问问题出在了哪个地方啊