首先明确this.$route.push() =>本身返回的也是Promise对象
问题:执行函数后只输出444和666 但是不执行push跳转
logout() {
this.$store.dispatch("logout");
console.log(444) //444
this.$router.push('/selectLogin') //不执行
console.log(6666) //6666
},
},
解决:
1.dispatch和router联合使用的bug dispatch加await可解决
async logout() {
//退出登录
await this.$store.dispatch("logout");
//跳转到个人页面
this.$router.push('/selectLogin') //他是受dispatch(actions中的返回值影响的)
},
加判断
async logout() {
//退出登录
try {
await this.$store.dispatch("logout");
this.$router.push('/home') //这样返回的成功promise被try包住可以正常执行
} catch (error) {
console.log(error);
}
//跳转到个人页面
},
},