2017-06-26 4 views
0

I nuxtjsを使用しています、私は彼がLOGGEDIN後にユーザーをリダイレクトする、リダイレクト()メソッドは、私の関数内で動作していない:fetchメソッドではなくコンポーネントメソッドでnuxtjsでリダイレクトを行う方法は?

loginUser: function() { 
    if (this.isValid) { 
     return axios.post(`/user/login`, {email: this.login.email, password: this.login.password}) 
     .then((res) => { 
      let response = res.data 
      if (typeof response.token !== 'undefined') { 
      setToken(response.token) 
      window.location.href = '/' 
      } 
     }).catch((e) => { 
      console.log(e.message) 
     }) 
    } 
    } 

はまた、これがために働い

loginUser: function() { 
    if (this.isValid) { 
     return axios.post(`/user/login`, {email: this.login.email, password: this.login.password}) 
     .then((res) => { 
      let response = res.data 
      if (typeof response.token !== 'undefined') { 
      console.log('loggedin') 
      this.props.url.replace('/') 
      } 
     }).catch((e) => { 
      console.log(e.message) 
     }) 
    } 
    } 

答えて

1

を働いていないURLプロパティにアクセス私

 loginUser: function() { 
    if (this.isValid) { 
     return axios.post(`/user/login`, {email: this.login.email, password: this.login.password}) 
     .then((res) => { 
      let response = res.data 
      if (typeof response.token !== 'undefined') { 
      setToken(response.token) 
      console.log('loggedin') 
      this.$router.replace('/') 
      } 
     }).catch((e) => { 
      console.log(e.message) 
     }) 
    } 
    } 
関連する問題