0
点赞
收藏
分享

微信扫一扫

es7如何使用await发送请求

曾宝月 2022-09-01 阅读 27

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"
});
}
}

遇见问题,这是你成长的机会,如果你能够解决,这就是收获。


作者:晚来南风晚相识​

本文版权归作者所有,欢迎转载,未经作者同意须保留此段声明,在文章页面明显位置给出原文连接

如果文中有什么错误,欢迎指出。以免更多的人被误导。



举报

相关推荐

0 条评论