上传代码
This commit is contained in:
42
uniapp04/pages/forums/forums.vue
Normal file
42
uniapp04/pages/forums/forums.vue
Normal file
@ -0,0 +1,42 @@
|
||||
<template>
|
||||
<!-- 测试页面 -->
|
||||
<view class="cart-page">
|
||||
<view v-for="(item, index) in menuItems" :key="index">
|
||||
<view>{{ item.name }} - {{ item.price }}元</view>
|
||||
<button @click="addToCart(item)">+</button>
|
||||
</view>
|
||||
|
||||
<!-- 购物车列表 -->
|
||||
<view v-if="cart.length > 0">
|
||||
<view>购物车中的商品:</view>
|
||||
<view v-for="(cartItem, cartIndex) in cart" :key="cartIndex">
|
||||
{{ cartItem.name }} - {{ cartItem.price }}元
|
||||
<button @click="removeFromCart(cartIndex)">-</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
menuItems: [
|
||||
{ name: '牛肉面', price: 18 },
|
||||
{ name: '炒饭', price: 15 },
|
||||
|
||||
],
|
||||
cart: []
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
addToCart(item) {
|
||||
this.cart.push({ ...item });
|
||||
},
|
||||
removeFromCart(index) {
|
||||
this.cart.splice(index, 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user