vuejs this.$router.push() has no effect - vuejs
世界只因有你
世界只因有你 2017-05-19 10:22:22
0
2
549
login() {
        if(this.email.length > 0 && this.password.length >0) {
            this.$http.post('/api/login', {
                user: this.email,
                password: this.password
            })
            .then(res => {
                let userPwd = res.data
                if(this.password == userPwd) {
                    this.$router.push("/")
                } else {
                    alert("错误,请重新输入!")
                }
            })
            .catch(err => {
                console.log(err)
            })
        } else {
            alert("输入错误!")
        }
        }

this.$router.push("/") does not jump to the homepage, but becomes like this: http://127.0.0.1:8080/login?email=yejia@qq.com&password=123456 , what's wrong?

世界只因有你
世界只因有你

reply all(2)
洪涛

The this point you have here is no longer the object of vue, you can change it like this

login() {
    const that = this;
    if(this.email.length > 0 && this.password.length >0) {
        this.$http.post('/api/login', {
            user: this.email,
            password: this.password
        })
        .then(res => {
            let userPwd = res.data
            if(this.password == userPwd) {
                that.$router.push("/")
            } else {
                alert("错误,请重新输入!")
            }
        })
        .catch(err => {
            console.log(err)
        })
    } else {
        alert("输入错误!")
    }
    }
世界只因有你

Is it possible that it has jumped, but the homepage judged that you are not logged in, and then jumped back.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template