使用自定义tabbar,在tab页中使用this.getTabBar()一直返回null,什么原因?
使用自定义tabbar,在使用的时候,发现菜单点击会发生错乱,于是上网查了相关信息,发现是因为没有在每个tab页面中添加this.getTabBar()这一段代码,于是就加上了这段代码。如下:
onShow: function () {
console.log(this.getTabBar());
if (typeof this.getTabBar === 'function' &&
this.getTabBar()) {
this.getTabBar().setData({
selected: 1
})
}
}
但是加完这段代码后,this.getTabBar()一直返回null。
![](https://image.wxopen.club/content_fe4dd390-9dd4-11ea-8e6d-001a7dda7111.png)
返回结果:
![](https://image.wxopen.club/content_fee9440c-9dd4-11ea-940d-001a7dda7111.png)
。
我自定义的tabbar是这样调用的:
![](https://image.wxopen.club/content_ffdc3b74-9dd4-11ea-9fd3-001a7dda7111.png)
![](https://image.wxopen.club/content_00c7df46-9dd5-11ea-9f84-001a7dda7111.png)
![](https://image.wxopen.club/content_018c7e3a-9dd5-11ea-ac90-001a7dda7111.png)
请问有大神可以解决吗?搞了一天没搞出来。