如何获得多层嵌套剪头函数的返回值?

问题描述

项目基于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'
    }
}

}

自己也觉得代码问题不小,但翻了一些资料还没找到解决办法……
请大佬指导学习一下

阅读 1.6k
1 个回答
const store = new Vuex.Store({

actions:{
    main(context, payload){
       return childA().then(() => {
           return childB().then(() => {
                if(payload == "planA"){
                   return get().then(result => {
                        //do something
                        //我想要这里有一个返回值return
                        return "A";
                    });
                }
            });
        });
    }
}
});

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题