问题描述
项目基于vue + vuex
在vuex中有一个多层嵌套请求函数,想要获得中间某一层的返回值
相关代码
const store = new Vuex.Store({
actions:{
main(context, payload){
childA().then(() => {
...
childB().then(() => {
...
if(payload == "planA"){
get().then(result => {
//do something
//我想要这里有一个返回值return
return "A";
});
}
});
});
}
}
});
想要在实例中获得返回值,但没有成功
//index.vue
export default {
mounted:function(){
this.main('planA');
},
methods:{
async main(status){
let statcode = await this.$store.dispatch('main',status);
console.log(statcode) //undefind,期待返回一个'A'
}
}
}
自己也觉得代码问题不小,但翻了一些资料还没找到解决办法……
请大佬指导学习一下