mini_code/miniprogram/custom-tab-bar/index.ts

47 lines
912 B
TypeScript

// custom-tab-bar/index.ts
Component({
/**
* 组件的属性列表
*/
properties: {
},
/**
* 组件的初始数据
*/
data: {
active: 0,
pageList: [{
url: '/pages/index/index'
},
{
url: '/pages/cart/cart'
},
{
url: '/pages/setting/setting'
},
{
url: '/pages/my/my'
}]
},
/**
* 组件的方法列表
*/
methods: {
changePage(e: any) {
getApp().globalData.active = e.detail;
wx.switchTab({
url: this.data.pageList[e.detail].url,
})
},
init() {
const page = getCurrentPages().pop();
this.setData({
active: this.data.pageList.findIndex(item => item.url === '/' + `${page?.route}`)
})
}
}
})