food_wechat/components/tabbar/tabbar.vue
szdot 78f4c8b037 【类 型】:fix
【主	题】:tabbar切换时 激活项的正确更新
【描	述】:
	[原因]:tabbar navigateBack时 无法正确切换到正确的激活项
	[过程]:
	[影响]:
【结	束】

# 类型 包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
2024-05-30 21:52:53 +08:00

51 lines
1.0 KiB
Vue

<template>
<view>
<u-tabbar :value="current" @change="handleTabChange" :fixed="true" :placeholder="true"
: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 {}
},
computed: {
current() {
return this.$store.state.tabbarCurrent
}
},
methods: {
handleTabChange(name) {
// 更新当前选中的 tab 索引
if (this.current === name) {
return
}
this.$store.commit('setTabbarCurrent', name)
if (name === 0) {
uni.redirectTo({
url: '/pages/index/index'
})
} else if (name === 1) {
uni.navigateTo({
url: '/pages/shop/list'
})
} else if (name === 2) {
uni.redirectTo({
url: '/pages/main/index'
})
}
},
}
}
</script>
<style>
</style>