gpt4 book ai didi

vue.js - vue-tables-2 如何处理模块中的 ROW_CLICK 事件?(vuex)

转载 作者:搜寻专家 更新时间:2023-10-30 22:47:41 24 4
gpt4 key购买 nike

我有一个名为“csv”的模块,用于处理 csv 文件,还有一个 vue-tables-2使用 vuex:

存储结构:

-store
-modules
-csv.js
-index.js

index.js:

Vue.use(Vuex)

const store = new Vuex.Store({
modules: {
commons,
ldap,
csv <---- I want to execute the mutation in this module
},
mutations: {
["csvTable/ROW_CLICK"](state, data){
<---- but now it's running here
},
}
})

csv.js

// initial state
const state = {
//...
}

// getters
const getters = {
//...
}

// mutations
const mutations = {
["csvTable/ROW_CLICK"](state, data){
< ---I want to execute the mutation here
}
}

export default {
//...
}

所以我想知道如何在 csv 模块中执行 ROW_CLICK 突变。

我以为我可以这样做:

index.js:

  ["csvTable/ROW_CLICK"](state, data){
this.commit(csv/ROW_CLICK, data);
},

但我认为这不是最好的方法。

谢谢。

最佳答案

Learn to use actions.It is recommended to execute your mutations through actions always.

csv.js 中添加如下操作:

   actions: {
callMutation({commit}, pass_property){ //pass_property is passed to action
commit('the_mutation_you_want_to_Call',pass_property)
}
}

提交对象对于提交突变的操作也是必需的。但是,如果您愿意,您也可以在操作中使用 getter 和状态。见下文:

示例:

  actions: {
actionName({commit,getters,state}) {}
}

关于vue.js - vue-tables-2 如何处理模块中的 ROW_CLICK 事件?(vuex),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49633306/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com