40 lines
1.0 KiB
JavaScript
40 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) {
|
||
|
console.log('点击了')
|
||
|
const index = e.currentTarget.dataset.index;
|
||
|
const pagePath = this.data.tabList[index].pagePath;
|
||
|
console.log(index, pagePath)
|
||
|
wx.switchTab({
|
||
|
url: '/' + pagePath
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
});
|