在nuxt注销后如何重定向到主页?
How to redirect to home page after logout in nuxt?
登录站点后,当我单击特定按钮时,用户从站点注销到主页。
这是我的 template
代码:
<template>
<nav id="header" class="navbar navbar-expand header-setting">
<div class="main-content">
<div class="notification" @click="LogOut()"></div>
</div>
</div>
</nav>
</template>
这是我的 script
代码:
export default {
name: 'HeadeAfterLogin',
methods: {
LogOut() {
localStorage.removeItem('token')
}
}
}
谁能帮我完成注销功能?
在您的组件中,您可以访问 this.$router
所以你可以轻松做到:
export default {
name: 'HeadeAfterLogin',
methods: {
LogOut() {
localStorage.removeItem('token')
this.$router.push('/')
}
}
}
我正在做的是:
分量:
### html
<a href="#" class="dropdown-item" @click.prevent="signOut">LogOut</a>
### script
export default {
methods: {
signOut() {
this.$auth.logout();
}
}
}
nuxt.config.js
auth: {
strategies: {
...
},
redirect: {
login: '/login',
logout: '/login', # after logout, user will be redirected here.
home: '/'
},
}
登录站点后,当我单击特定按钮时,用户从站点注销到主页。
这是我的 template
代码:
<template>
<nav id="header" class="navbar navbar-expand header-setting">
<div class="main-content">
<div class="notification" @click="LogOut()"></div>
</div>
</div>
</nav>
</template>
这是我的 script
代码:
export default {
name: 'HeadeAfterLogin',
methods: {
LogOut() {
localStorage.removeItem('token')
}
}
}
谁能帮我完成注销功能?
在您的组件中,您可以访问 this.$router
所以你可以轻松做到:
export default {
name: 'HeadeAfterLogin',
methods: {
LogOut() {
localStorage.removeItem('token')
this.$router.push('/')
}
}
}
我正在做的是:
分量:
### html
<a href="#" class="dropdown-item" @click.prevent="signOut">LogOut</a>
### script
export default {
methods: {
signOut() {
this.$auth.logout();
}
}
}
nuxt.config.js
auth: {
strategies: {
...
},
redirect: {
login: '/login',
logout: '/login', # after logout, user will be redirected here.
home: '/'
},
}