dapaijizhang3/components/custom-tabbar/custom-tabbar.js

60 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2025-11-20 16:42:59 +08:00
// components/custom-tabbar/custom-tabbar.js
Component({
data: {
selected: 0,
color: "#666666",
selectedColor: "#667eea",
list: [
{
pagePath: "/pages/index/index",
text: "打牌记账",
iconPath: "../images/index.png",
selectedIconPath: "../images/index_active.png"
},
{
pagePath: "/pages/stats/personal/personal",
text: "统计分析",
iconPath: "../images/record.png",
selectedIconPath: "../images/record-active.png"
},
{
pagePath: "/pages/profile/index/index",
text: "我的",
iconPath: "../images/my.png",
selectedIconPath: "../images/my-active.png"
}
]
},
properties: {
selected: {
type: Number,
value: 0
}
},
lifetimes: {
attached() {
// 组件初始化时更新选中状态
this.setData({
selected: this.data.selected
})
}
},
methods: {
switchTab(e) {
const index = e.currentTarget.dataset.index
const pagePath = this.data.list[index].pagePath
// 触发事件通知父组件
this.triggerEvent('tabchange', { index, pagePath })
// 切换页面
wx.switchTab({
url: pagePath
})
}
}
})