当前位置:   article > 正文

tabbar点击两次图标才正确切换_微信小程序自定义tabbartabbar图标切换 要点击两次才能有选中状态

微信小程序自定义tabbartabbar图标切换 要点击两次才能有选中状态

第一种解决办法

onChange(event) {
	this.setData({
  	active: event.detail,
  });
  wx.switchTab({
  	url: this.data.list[event.detail].url,
  });
},
init() {
	const page = getCurrentPages().pop();
  this.setData({
  	active: this.data.list.findIndex(item => item.url === `/${page.route}`)
  })
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

第二种解决方法

在对应的使用tabbar页面编写

/**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    // 通过 getTabBar 接口获取组件实例,并调用 setData 更新选中态
    this.getTabBar().setData({active: 0})
  },
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号