vuejs如何利用async/await实现同步 发布时间:2025/01/14 vuejs如何利用async/await实现同步,下面编程教程网小编给大家详细介绍一下具体实现代码! 具体代码如下: 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); } }) } }) } } 复制代码 以上是编程学习网小编为您介绍的“vuejs如何利用async/await实现同步”的全面内容,想了解更多关于 vuejs 内容,请继续关注编程基础学习网。