success: function (res) {
app.globalData.number = res.data.phoneNumber;
console.log(app.globalData.number);
wx.switchTab({
url: 'pages/index/index',
success(res) {
let page = getCurrentPages().pop();
if (page == undefined || page == null) {
return
}
page.onLoad();
}
})
}
这是tabbard的list
"list": [
{
"pagePath": "pages/index/index",
"text": "项目介绍",
"iconPath": "/images/pro1.png",
"selectedIconPath": "/images/pro.png"
},
{
"pagePath": "pages/index2/analysis",
"text": "累计处理量",
"iconPath": "/images/addup1.png",
"selectedIconPath": "/images/addup.png"
},
{
"pagePath": "pages/index3/index3",
"text": "我的反馈",
"iconPath": "/images/my1.png",
"selectedIconPath": "/images/my.png"
}
]
参考GPT和自己的思路:
根据你提供的代码,wx.switchTab函数本身并没有问题,但可能存在以下几种原因导致它失效:
tabBar的配置路径不正确,需要检查是否正确配置了pages/index/index、pages/index2/analysis、pages/index3/index3三个页面的路径。
tabBar被覆盖了,建议在app.json配置文件中设置"window"属性中的"tabBar"的"zIndex"为999,确保tabBar层级最高。
若上面两种情况都不是问题,那可能是因为你使用了getCurrentPages().pop()方法,取到的是当前页面的前一页面,而前一页面并没有onLoad()事件,导致switchTab失效。建议修改代码,将页面刷新的逻辑写在调用wx.switchTab()函数的页面中。
希望我的答复能对你有所帮助。