39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
Component({
|
|
properties: {
|
|
tabList: {
|
|
type: Array,
|
|
value: []
|
|
},
|
|
color: {
|
|
type: String,
|
|
value: '#515151'
|
|
},
|
|
selectedColor: {
|
|
type: String,
|
|
value: '#FE9944'
|
|
}
|
|
},
|
|
data: {},
|
|
attached() {
|
|
// 获取当前页面路径
|
|
const pages = getCurrentPages();
|
|
const currentPage = pages[pages.length - 1];
|
|
const currentPath = `/${currentPage.route}`;
|
|
const index = this.data.tabList.findIndex(item => item.pagePath === currentPath);
|
|
if (index !== -1) {
|
|
this.setData({
|
|
selected: index
|
|
});
|
|
}
|
|
},
|
|
methods: {
|
|
switchTab(e) {
|
|
const index = e.currentTarget.dataset.index;
|
|
const pagePath = this.data.tabList[index].pagePath;
|
|
console.info('tabbar切换', index, pagePath)
|
|
wx.switchTab({
|
|
url: '/' + pagePath
|
|
});
|
|
}
|
|
}
|
|
}); |