作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 https://championswimmer.in/vuex-module-decorators 中的 vuex-module-decorators .
假设我的模块状态有一个 Prop dir
这是一个字典:{[key: string]: string}
我可以使用 @MutationAction
更新该字典的元素?下面的代码不正确,但希望能理解我的意思。
export default class Module extends VuexModule {
dir: {[key: string]: string}
@MutationAction(???)
updateDir(keyValue) {
return keyValue // ???
}
}
@MutationAction
,它需要什么参数以及它提交的实际突变是什么?
最佳答案
这是你应该做的 -
export default class Module extends VuexModule {
dir: {[key: string]: string}
@MutationAction(['dir'])
async updateDir(keyValue) {
const currDir = this.dir
// do any async work (network req) here
currDir['myKey'] = keyValue
return ( { dir: currDir } )
}
}
export default class Module extends VuexModule {
dir: {[key: string]: string}
@Mutation
async updateDir(keyValue) {
this.dir.myKey = keyValue
}
}
vuex-module-decorators
的作者
关于typescript - 如何在 vuex-module-decorators 中使用 MutationAction?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55730545/
我是一名优秀的程序员,十分优秀!