2025年02月08日 建站教程
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); } }) } }) } }
本文链接:http://so.lmcjl.com/news/22771/