food_wechat/components/tabbar/tabbar.vue

51 lines
1.0 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 class="fz24" text="首页" icon="home"></u-tabbar-item>
<u-tabbar-item class="fz24" text="点餐" icon="grid"></u-tabbar-item>
<u-tabbar-item class="fz24" text="我的" icon="account"></u-tabbar-item>
</u-tabbar>
</view>
</template>
<script>
export default {
name: "tabbar",
data() {
return {}
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>