Browse Source

refactor(自定义标签栏): 使用计算属性替代ref获取购物车数量

将购物车数量从ref改为从store中获取的计算属性,保持数据同步性
master
wei 1 week ago
parent
commit
858aeba102
  1. 8
      components/custom-tab-bar/my-tab-bar.vue

8
components/custom-tab-bar/my-tab-bar.vue

@ -1,10 +1,13 @@
<script setup>
import { ref } from "vue";
import { computed, ref } from "vue";
import useStore from "@/store";
const props = defineProps({
tabIndex: String | Number,
});
const store = useStore();
/**
* 底部导航栏下标
*/
@ -20,7 +23,7 @@ const activeColor = "#06CA64";
/**
* 购物车数量
*/
const cartCount = ref(0);
const cartCount = computed(() => store.count);
/**
* 底部导航栏标签信息
@ -93,6 +96,7 @@ function onChangeTab(index) {
<view class="name" :style="{ color: activeTab === index ? activeColor : inactiveColor }">
{{ tab.text }}
</view>
<view v-if="index === 3 && cartCount !== 0" class="badge">
{{ cartCount }}
</view>

Loading…
Cancel
Save