food_wechat/components/tabbar/tabbar.vue

65 lines
1.2 KiB
Vue
Raw Normal View History

2024-05-30 16:22:41 +08:00
<template>
<view>
<u-tabbar :value="current" @change="handleTabChange" :fixed="true" :placeholder="true"
2024-05-30 16:22:41 +08:00
:safeAreaInsetBottom="true" activeColor="#D43030">
<u-tabbar-item v-for="(item,index) in tabList" :key="index" class="fz28" :text="item.name"
:icon="item.icon"></u-tabbar-item>
2024-05-30 16:22:41 +08:00
</u-tabbar>
</view>
</template>
<script>
export default {
name: "tabbar",
data() {
return {
tabList: [ //tabbar列表
{
'name': '首页',
'icon': 'home'
},
{
'name': '点餐',
'icon': 'grid'
},
{
'name': '我的',
'icon': 'account'
}
]
}
2024-05-30 16:22:41 +08:00
},
computed: {
current() {
return this.$store.state.tabbarCurrent
2024-05-30 16:22:41 +08:00
}
},
methods: {
handleTabChange(name) {
// 更新当前选中的 tab 索引
if (this.current === name) {
return
}
this.$store.commit('setTabbarCurrent', name)
2024-05-30 16:22:41 +08:00
if (name === 0) {
uni.redirectTo({
url: '/pages/index/index'
})
2024-05-30 16:22:41 +08:00
} else if (name === 1) {
uni.navigateTo({
url: '/pages/shop/list'
})
2024-05-30 16:22:41 +08:00
} else if (name === 2) {
uni.redirectTo({
url: '/pages/main/index'
})
2024-05-30 16:22:41 +08:00
}
},
}
}
</script>
<style>
</style>