赞
踩
以这两个页面为例子
(1)tabBar=>index.js
data: { active: 0, list: [ { pagePath: "/pages/index/index", text: "工作台", icon: "home-o", }, { pagePath: "/pages/logs/logs", text: "我的", icon:"user-o", }, ] }, methods: { onChange(e) { this.setData({ active: e.detail }); this.setData({ active: e.detail }); wx.switchTab({ url: this.data.list[e.detail].pagePath }); }, init() { const page = getCurrentPages().pop(); this.setData({ active: this.data.list.findIndex(item => item.pagePath === `/${page.route}`) }); }, }
(2)index页面
onShow() {
this.getTabBar().init({
active: 0
})
},
(3)log页面
onShow() {
this.getTabBar().init({
active: 1
})
},
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。