Small program custom tabbar double-click to switch problem summary

Problem Description

When the custom tabbar of the applet is used in accordance with the official document, there will be a problem that the bottom tabbar cannot be switched by clicking, and the bottom tabbar can not be switched by double-clicking. I did not find the reason. I directly read a relatively good method from the Internet to warn latecomers...

Solution
  • Add the code inside the onshow method of the page to be jumped to at the bottom of the tabbar
 if(typeof this.getTabBar === 'function' && this.getTabBar()) {
    
    
      
      this.getTabBar().setData({
    
    
        selected: 1
      })
    }

selected为要切换的tabbar 的索引

  • You can also encapsulate it in app.json and call it in the show method of the pages you want to jump to.
  /**
   * 修复 自定义 tarbar 双击才能切换的bug
   * @param {*} ctx 上下文
   * @param {*} idx 索引
   */
  customTarbarBugRepair(ctx, idx){
    
    
    if(typeof ctx.getTabBar === 'function' && ctx.getTabBar()) {
    
    
      
      ctx.getTabBar().setData({
    
    
        selected: idx
      })
    }
  }

Guess you like

Origin blog.csdn.net/ITzhongzi/article/details/114083629