登录功能 在action中发送请求成功后触发回调函数 提示信息
这样能否可行
vue
let param = this.loginFrom;
this.$store.dispatch('getUserInfo',param, function(result) {
console.log("来到回调函数");
if (result.data.code) {
this.loading = false;
this.$router.replace('/home')
this.$message({
type:'success',
message:'登陆成功'
});
} else {
this.loading = false;
this.$message({
type:'error',
message:result.data.msg
});
}
});
action
async getUserInfo({commit}, param ,callback){
if(param.role === '0'){ //老师身份登录
const teacher = {
teacherName: param.username,
password: param.password,
};
const result = await TeacherLogin(teacher);
if (result.data.code) {
const userInfo = result.data.datas;
commit(RECEIVE_USER_INFO,{userInfo})
console.log("接下来执行回调函数");
callback && callback(result);
}
}
},