gpt4 book ai didi

node.js - 如何在 nuxtjs 中的组件方法而不是 fetch 方法中进行重定向?

转载 作者:太空宇宙 更新时间:2023-11-04 00:20:22 24 4
gpt4 key购买 nike

我正在使用 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)
})
}
}

最佳答案

这对我有用

      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)
})
}
}

关于node.js - 如何在 nuxtjs 中的组件方法而不是 fetch 方法中进行重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44770213/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com