在vuex中这样写promise对吗?为什么获得的结果是undefined?
我认为.then应该写在上图倒数第二行蓝括号后边。
在vuex中这样写promise对吗?为什么获得的结果是undefined?
我认为.then应该写在上图倒数第二行蓝括号后边。
是对的哦,首先输出下你这里response的值,看看接口到底有没值先,如果没值那这里就是问题了,那你就要看看你的l请求有没成功,login函数为何没返回值;如果说有值,那么就是你的调用问题了,调用是类似如此吗,this.$store可以不用管,可能你是store或者其他,这个没关系值对就行。关键是是否使用dispatch
this.$store.dispatch('user/login', loginInfo).then((res) => {
console.log('这里拿到res数据,也就是你vuex定义里面的response')
})
或者是async函数中使用await
let res = await this.$store.dispatch('user/login', loginInfo)
console.log('这个时候也能拿到值')