onShow() {
this.getTabBar().setData({
})
}
问题背景:
自定义的 tabbar 在点击tab进行跳转的时候 custom-tab-bar 这个组件也会刷新页面,所以需要连续点击两次icon才会变为选中状态。所以需要将选中的方法定义在每个tab页的onShow方法中,加了之后 console.log(this.getTabBar())
时打印结果为undefind
解决方法如下:
if (typeof this.$mp.page.getTabBar === 'function' &&
this.$mp.page.getTabBar()) {
this.$mp.page.getTabBar().setData({
selected: 0
})
}