小编Dr.*_*oob的帖子

this.$auth.loggedIn 返回 false

当我从 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)

vue.js nuxt.js

2
推荐指数
1
解决办法
6113
查看次数

标签 统计

nuxt.js ×1

vue.js ×1