
vuejs如何利用async/await实现同步,下面web建站小编给大家详细介绍一下具体实现代码!
具体代码如下:
data() {
return {
userInfo: {
username: ''
},
}
},
methods:{
async getUserInfo(params) {
let _this = this;
let isSuccess = false;
await this.axios({
url: "login",
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
method: "post",
params: {
'userName': _this.form.username
}
}).then(function (resp) {
_this.userInfo = resp.data;
console.log("1");
isSuccess = true;
});
return isSuccess;
},
onSubmit(formName) {
let _this = this;
this.getUserInfo(_this.form.username).then(function (result) {
if (result) {
_this.$refs[formName].validate((valid) => {
if (valid) {
console.log("2");
console.log(_this.userInfo);
}
})
}
})
}
}
async和await是es6语法还是es7语法(附代码介绍)
上面是“vuejs如何利用async/await实现同步”的全面内容,想了解更多关于 vuejs 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_3447.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

DedeCms开启多站点支持绝对网址后生成RSS错误的修
推荐一款可免费商用的音效素材下载网站——Freesound(音频片段、样本、录音等)