search

Home  >  Q&A  >  body text

vuejs this.$router.push() has no effect - vuejs

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?

世界只因有你世界只因有你2836 days ago553

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-05-19 10:24:22

    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("输入错误!")
        }
        }

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-19 10:24:22

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

    reply
    0
  • Cancelreply