handleLogin() {
this.$http.post("login", this.formLabelAlign).then(res => {
const {
data,
meta: { msg, status }
} = res.data;
if (status === 200) {
this.$message({
showClose: true,
message: msg,
type: "success"
});
this.$router.push({ name: "home" });
} else {
this.$message({
showClose: true,
message: msg,
type: "error"
});
}
});
}
使用await的方式
简记在函数的前面使用async
在请求时,使用await。然后用一个变量进行接收哈。
async handleLogin() {
const res = await this.$http.post("login", this.formLabelAlign);
const {
data,
meta: { msg, status }
} = res.data;
if (status === 200) {
this.$message({
showClose: true,
message: msg,
type: "success"
});
this.$router.push({ name: "home" });
} else {
this.$message({
showClose: true,
message: msg,
type: "error"
});
}
}