【发布时间】:2020-06-09 21:27:38
【问题描述】:
在Vuex和View中,如何在...mapActions(["getConfig"])之间设置值或执行函数?
例如:
methods: {
this.theValue=true
...mapActions(["getConfig"])
this.theValue=false
}
【问题讨论】:
-
你不能在对象字面量声明中执行任意代码。
在Vuex和View中,如何在...mapActions(["getConfig"])之间设置值或执行函数?
例如:
methods: {
this.theValue=true
...mapActions(["getConfig"])
this.theValue=false
}
【问题讨论】:
将回复写成评论太短了。
您需要调用一个操作,但还需要设置一些特定于您的组件的值。您需要包装您的操作调用,例如
{
// ...
methods:{
...mapActions(["getConfig"]),
doGetConfig: async function(){
this.theValue = true;
await this.getConfig();
this.theValue = false;
}
}
}
您必须假设所有操作都是异步的,因此async / await。
getConfig与您的问题无关,但 getConfig 听起来是一个吸气剂名称。我写了上面的答案,假设它类似于loadConfig
【讨论】: