优惠券的使用功能优化
This commit is contained in:
@@ -91,7 +91,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { ref, onMounted, inject } from 'vue'
|
||||
import { ArrowLeft, Star, Clock, Collection, ShoppingCart, Right } from '@element-plus/icons-vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
@@ -99,6 +99,9 @@ import { productApi, type ProductVO } from '@/api/product'
|
||||
import { fileApi } from '@/api/index'
|
||||
import { cartApi } from '@/api/cart'
|
||||
|
||||
// 注入更新购物车数量的方法
|
||||
const updateCartCount = inject<() => Promise<void>>('updateCartCount', async () => {})
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
@@ -201,6 +204,8 @@ const handleAddToCart = async () => {
|
||||
console.log('开始调用cartApi.addToCart')
|
||||
await cartApi.addToCart({ productId: product.value.id, quantity: 1 })
|
||||
console.log('调用cartApi.addToCart成功')
|
||||
// 实时更新购物车角标数字
|
||||
await updateCartCount()
|
||||
ElMessage.success(`已将 ${product.value.title} 添加到购物车`)
|
||||
} catch (error) {
|
||||
console.error('添加到购物车失败:', error)
|
||||
@@ -216,6 +221,8 @@ const handleBuyNow = async () => {
|
||||
console.log('开始调用cartApi.addToCart')
|
||||
await cartApi.addToCart({ productId: product.value.id, quantity: 1 })
|
||||
console.log('调用cartApi.addToCart成功')
|
||||
// 实时更新购物车角标数字
|
||||
await updateCartCount()
|
||||
// 跳转到购物车页面
|
||||
console.log('开始跳转到购物车页面')
|
||||
router.push('/cart')
|
||||
|
||||
Reference in New Issue
Block a user