Promise
async getUserInfo({commit}, param ){
return new Promise(resolve =>{
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("接下来执行回调函数");
resolve(resolve)
}
}
})
},
this.$store.dispatch('getUserInfo',param).then(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
});
}
}
})
回调
let param = this.loginFrom;
const callback = 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
});
}
}
this.$store.dispatch('getUserInfo',{callback, param});
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);
}
}
},
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…