const app = getApp()
Component({
data: {
activate: wx.getStorageSync('activate') || 0,
color: "#7A7E83",
selectedColor: "#3cc51f",
list: [
{
"text": "首页",
"pagePath": "/pages/index/index",
"iconPath": "/assets/images/icons/home.png",
"selectedIconPath": "/assets/images/icons/activate/home.png"
},
{
"text": "成交价",
"pagePath": "/pages/transaction/index/transaction",
"iconPath": "/assets/images/icons/transaction.png",
"selectedIconPath": "/assets/images/icons/activate/transaction.png"
},
{
"text": "大数据",
"pagePath": "/pages/top/index/top",
"iconPath": "/assets/images/icons/top.png",
"selectedIconPath": "/assets/images/icons/activate/top.png"
},
{
"text": "社区",
"pagePath": "/pages/article/index/article",
"iconPath": "/assets/images/icons/article.png",
"selectedIconPath": "/assets/images/icons/activate/article.png"
},
{
"text": "我",
"pagePath": "/pages/admin/index/admin",
"iconPath": "/assets/images/icons/admin.png",
"selectedIconPath": "/assets/images/icons/activate/admin.png"
}
]
},
attached() {
},
methods: {
switchTab(e) {
const index = e.currentTarget.dataset.index
const path = e.currentTarget.dataset.path
wx.setStorage("activate",index)
wx.switchTab({
url:path
})
this.setData({
activate: wx.getStorage("activate")
})
}
}
})
页面是大数据,但是跳转玩页面后 索引激活有变成了首页,尝试了全局变量和本地报错索引 全部都是不行,如果每个页面我都跳转完之后,在点击第二次那索引就全部乱了,没有任何规律,我下载官方的代码可以运行,放到我的项目就不行,所以正常运行的代码 放到我的项目 就出现这个问题
你要在tabbar对应的页面赋值,比如“大数据”页面的onShow或者onload
this.getTabbar.setData({actice: 2})
activate: 0,索引直接设置成0
切换点击:switchTab(e) {
const index = e.currentTarget.dataset.index
const path = e.currentTarget.dataset.path
this.setData({
activate: index
})
wx.switchTab({
url:path
})
}