<li class="cart_item clearfix" v-for="(product, index) in products" :key="index">
<div class="cart_item_text"><button type="button" class="btn btn-success" name="button" @click="increaseQuantity(index)"</button></div></li>
in this for loop has three products. And method called three times.
//script
methods: {increaseQuantity(index) {this.$store.dispatch("incrementQuantity", index);},}
//store.js
mutations:{
INCREMENT(state, index) {state.basket.items = state.basket.items.map(items => {state.basket.items[index].quantity +=1;return items;});},},
actions:{
incrementQuantity({ commit }, index) {commit("INCREMENT", index)},}
答案 0 :(得分:0)
In 突变不需要 map() 函数。它循环了 3 次,它给了我 +3 的数量。我不知道什么需要 map() 函数。请让我知道