es7如何使用await发送请求
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"
});
}
}
遇见问题,这是你成长的机会,如果你能够解决,这就是收获。
作者:晚来南风晚相识
出处:https://www.cnblogs.com/IwishIcould/
本文版权归作者所有,欢迎转载,未经作者同意须保留此段声明,在文章页面明显位置给出原文连接
如果文中有什么错误,欢迎指出。以免更多的人被误导。
出处:https://www.cnblogs.com/IwishIcould/
想问问题,打赏了卑微的博主,求求你备注一下的扣扣或者微信;这样我好联系你;(っ•̀ω•́)っ✎⁾⁾!
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,或者关注博主,在此感谢!
万水千山总是情,打赏5毛买辣条行不行,所以如果你心情还比较高兴,也是可以扫码打赏博主(っ•̀ω•́)っ✎⁾⁾!
想问问题,打赏了卑微的博主,求求你备注一下的扣扣或者微信;这样我好联系你;(っ•̀ω•́)っ✎⁾⁾!
支付宝
微信
如果文中有什么错误,欢迎指出。以免更多的人被误导。