第一种解决办法
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}`)
})
}
第二种解决方法
在对应的使用tabbar页面编写
/**
* 生命周期函数--监听页面显示
*/
onShow() {
// 通过 getTabBar 接口获取组件实例,并调用 setData 更新选中态
this.getTabBar().setData({active: 0})
},