21 lines
734 B
JavaScript
21 lines
734 B
JavaScript
const { tabForPage, paths } = require('../../utils/navigation');
|
|
Component({
|
|
data: { active: '' },
|
|
lifetimes: { attached: function() { this.syncActive(); } },
|
|
pageLifetimes: { show: function() { this.syncActive(); } },
|
|
methods: {
|
|
syncActive: function() {
|
|
var pages = getCurrentPages();
|
|
var current = pages[pages.length - 1];
|
|
this.setData({ active: tabForPage(current && current.route) });
|
|
},
|
|
navigate: function(e) {
|
|
var tab = e.currentTarget.dataset.tab;
|
|
if (!paths[tab]) return;
|
|
var pages = getCurrentPages();
|
|
// 当前主页面重复点击不重新加载。
|
|
if (pages.length && pages[pages.length - 1].route === paths[tab]) return;
|
|
wx.reLaunch({ url: '/' + paths[tab] });
|
|
}
|
|
} });
|