Vue.js: a this problem

goLogin() {
        console.log(url.loginIn)
         this.loading = true
        if (this.userInfo.phone == "" || this.userInfo.password == "") {
            this.$message.error("");
            this.loading = false
        } else {
            this.$axios.post(url.loginIn,{phone: this.userInfo.phone,password: this.userInfo.password})
                .then(response => {
                    console.log(response);
                    if (response.status == 200) {
                        this.loading = false
                        if (response.data.resultCode == 1) {
                            this.$message({message:"", type:"success"});
                        } else {
                            this.$message.error("");
                            return
                            this.loading = false
                        }
                    } 
                })
                .catch(function(error) {
                    console.log(error);
                    this.loading = false
                    alert("")
                       
                });
        }
    },
    
    
    this.loading = true.catch()this.loading = false:TypeError: Cannot set property "loading" of undefined
Aug.13,2021

.catch((error) => {
                    console.log(error);
                    this.loading = false
                    alert('')
                       
                });

arrow function, because of the arrow function you used above, you can
clipboard.png


try to write the functions in catch as arrow functions. The orientation of this may be lost

.
Menu