我使用nuxtjs,我想在登录后重定向用户,redirect()方法在我的函数内部无效:
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)
})
}
}
同时访问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') {
console.log('loggedin')
this.props.url.replace('/')
}
}).catch((e) => {
console.log(e.message)
})
}
}
答案 0 :(得分:1)
这对我有用
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)
})
}
}