vuejs2 - VueJS 如何将两个参数传递给 Vuex 操作

标签 vuejs2 vuex

<button class="btn" @click="removeFromTheCart(index,item.price)">
  Remove
</button>

我将两个参数传递给我的操作removeFromTheCart

removeFromTheCart({ commit }, payload) {
  console.log("rooooooohhhhhoooow",payload)

当我在 vuex 存储中控制台记录我的有效负载时,它仅输出索引。 我的第二个参数不在输出中。

如何通过一个操作获取两个参数值?

最佳答案

您可以发送一个对象作为您的负载,如下所示:

<button class="btn" @click="removeFromTheCart({ index, price: item.price })">Remove</button>

并获取您商店中的数据:

removeFromTheCart({ commit }, { index, price }) {
  console.log('index', index, 'price', price);
}

关于vuejs2 - VueJS 如何将两个参数传递给 Vuex 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49998296/

相关文章:

javascript - 如何将数据从 vueJS 传递到 vuex

vue.js - VueJS |方法 "watch"在组件定义中具有类型 "object"

javascript - 正在为未受影响的其他组件触发 Vue 指令

javascript - vue.js $emit 自定义事件不工作

vue.js - 如何在VueJS中遍历数组的动态对象

javascript - 如何正确观察 Vuex 中的状态变化?

javascript - Vue 变量在 Vuex 中无法访问

vue.js - 从 vuex 中的模块 getter 访问根状态

vue.js - 如何解决nuxt.js中的最大调用堆栈大小超出错误

google-maps - 使用vue2-google-maps创建折线