Javascript 多次调用的方法 {state.basket.items[index].quantity+=1;return items;});},}, 行动:{ incrementQuantity({commit},index){commit(“INCREMENT”,index)},}

Javascript 多次调用的方法 {state.basket.items[index].quantity+=1;return items;});},}, 行动:{ incrementQuantity({commit},index){commit(“INCREMENT”,index)},},javascript,vue.js,Javascript,Vue.js,中的突变不需要map()函数。它循环三次,给我+3个数量。我不知道需要什么map()函数。请让我知道这很好⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀那么问题到底是什么呢?发布的代码似乎没有调用自己三次,因此应用程序的设置方式肯定有错误,或者您的鼠标按钮实际上有弹性?请使用CodePen、JSFIDLE或类似工具创建一个测试应用程序。我发现了我的错误。在store.js中,我使用了map()函数,它循环了三次。 <li class="cart_item clearfix" v-for=&qu

中的突变不需要map()函数。它循环三次,给我+3个数量。我不知道需要什么map()函数。请让我知道这很好⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀那么问题到底是什么呢?发布的代码似乎没有调用自己三次,因此应用程序的设置方式肯定有错误,或者您的鼠标按钮实际上有弹性?请使用CodePen、JSFIDLE或类似工具创建一个测试应用程序。我发现了我的错误。在store.js中,我使用了map()函数,它循环了三次。
<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)},}