<template>
<div id="app">
<h1>购物车</h1>
<div>
<p>购物车商品总数:{
{ itemCount }}</p>
<p>购物车总价:{
{ totalPrice }} 元</p>
</div>
<div>
<button @click="addItemToCart">添加商品</button>
<button @click="removeItemFromCart">删除商品</button>
</div>
</div>
</template>
<script>
import { mapState, mapActions } from 'vuex'
export default {
computed: {
// 使用命名空间,映射 cart 模块的状态
...mapState('cart', ['items']),
itemCount() {
return this.$store.getters['cart/itemCount'] // 获取购物车商品总数
},
totalPrice() {
return this.$store.getters['cart/totalPrice'] // 获取购物车总价
}
【7777777777777】
于 2025-02-10 16:53:18 首次发布
订阅专栏 解锁全文
141

被折叠的 条评论
为什么被折叠?



