当我从 nuxtjs 发送登录请求时,我在后端使用 laravel/passport 进行身份验证,并使用 nuxtjs 作为前端,如果登录成功,我将返回令牌和用户信息作为响应,然后用户将被重定向到/profile页面,但是/profile当我返回时在页面 中this.$auth.loggedIn我得到了false!
登录.vue
<script>
export default {
data() {
return {
auth: false,
email: "",
password:""
}
},
methods: {
async login() {
try {
const data = { email: this.email, password: this.password }
await this.$auth.loginWith('local', { data:data})
.then(() => this.$router.push('/profile'))
} catch (e) {
}
}
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
配置文件.vue
<template>
<div class="mt-6">loggedInUser: {{ loggedInUser }}</div>
</template>
<script>
export default{
data() {
return {
loggedInUser:this.$auth.loggedIn …Run Code Online (Sandbox Code Playgroud)