头发别掉 2020-02-13 15:51 采纳率: 0%
浏览 732

为什么我的wx.switchTab失效了

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"
  }
]
  • 写回答

1条回答 默认 最新

  • lshen01 2023-03-17 09:16
    关注

    参考GPT和自己的思路:

    根据你提供的代码,wx.switchTab函数本身并没有问题,但可能存在以下几种原因导致它失效:

    1. tabBar的配置路径不正确,需要检查是否正确配置了pages/index/index、pages/index2/analysis、pages/index3/index3三个页面的路径。

    2. tabBar被覆盖了,建议在app.json配置文件中设置"window"属性中的"tabBar"的"zIndex"为999,确保tabBar层级最高。

    3. 若上面两种情况都不是问题,那可能是因为你使用了getCurrentPages().pop()方法,取到的是当前页面的前一页面,而前一页面并没有onLoad()事件,导致switchTab失效。建议修改代码,将页面刷新的逻辑写在调用wx.switchTab()函数的页面中。

    希望我的答复能对你有所帮助。

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料