vuex的getters返回函数,把异步变同步,加了async / await 无效

vuex
getters:{
getTest:state=>{
returnasync()=>{
constresult=awaitnewPromise((resolve,reject)=>{
setTimeout(function(){
resolve('foo');
},3000);
})
returnresult
}
}
}
控制台运行
vue.$store.getters.getTest()//Promise {}
//我希望他返回`foo`
希望大佬帮我指正代码,十分感谢!
紫衣仙女
浏览 1915回答 2
2回答

holdtom

getTest:state=>{returnnewPromise((resolve,reject)=>{setTimeout(()=>{resolve('foo');},3000);});},(async()=>{constresult=awaitthis.$store.getters.getTest;console.log(result);//foo})();
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript