vue可以做同步,vue實作同步的方法:1、建立一個vue範例檔;2、透過「data(){return { userInfo: {id: '',username: '',password:'',avatar: '',},}}methods:{getUserInfo: function () {let _this = this;this.axios({...} )」實作同步即可。
##本教學操作環境:Windows10系統、Vue 3版、DELL G3電腦
vue可以做同步嗎?原始程式碼
data() { return { userInfo: { id: '', username: '', password: '', avatar: '', }, }}methods:{ getUserInfo: function () { let _this = this; this.axios({ url: "http://localhost:8088/verifyLogin", headers: { 'Content-Type': 'application/json;charset=utf-8' }, method: "post", params: { 'userName': _this.form.username } }).then(function (resp) { _this.userInfo = resp.data; console.log('11111111'); }) }, onSubmit(formName) { let _this = this; this.getUserInfo(); // 为表单绑定验证功能 this.$refs[formName].validate((valid) => { if (valid) { console.log("22222222"); console.log(_this.userInfo); } else { } }); }}
data() { return { userInfo: { id: '', username: '', password: '', avatar: '', }, }}methods:{ async getUserInfo(params) { let _this = this; let isSuccess = false; await this.axios({ url: "http://localhost:8088/verifyLogin", headers: { 'Content-Type': 'application/json;charset=utf-8' }, method: "post", params: { 'userName': _this.form.username } }).then(function (resp) { _this.userInfo = resp.data; console.log("11111111"); isSuccess = true; }); return isSuccess; }, onSubmit(formName) { let _this = this; this.getUserInfo(_this.form.username).then(function (result) { if (result) { // do sth. // 为表单绑定验证功能 _this.$refs[formName].validate((valid) => { if (valid) { console.log("22222222"); console.log(_this.userInfo); } } else { } }); } else { // do other sth. } }) }}
以上是vue可以做同步嗎的詳細內容。更多資訊請關注PHP中文網其他相關文章!