Vue.js Nuxt验证两个本地端点

Vue.js Nuxt验证两个本地端点,vue.js,nuxt.js,Vue.js,Nuxt.js,我想创建两个本地端点,如下所示: strategies: { localOne: { endpoints: { login: { url: "token/", method: "post", propertyName: "access" }, user: { url: "user/me/", method: "get", propertyName: false }, logout: false, } }, localTwo: {

我想创建两个本地端点,如下所示:

strategies: {
  localOne: {
    endpoints: {
      login: { url: "token/", method: "post", propertyName: "access" },
      user: { url: "user/me/", method: "get", propertyName: false },
      logout: false,
    }
  },
  localTwo: {
    endpoints: {
      login: { url: "user/token/", method: "post", propertyName: "access" },
      user: { url: "user/me/", method: "get", propertyName: false },
      logout: false,
    }
  }
},
但是我在控制台中遇到了以下问题

client.js?06a0:77 TypeError: Cannot read property 'mounted' of undefined
at Auth.mounted (auth.js?facc:112)
at Auth.setStrategy (auth.js?facc:108)
at Auth.loginWith (auth.js?facc:123)
at _callee3$ (log-in.vue?f35c:175)
at tryCatch (runtime.js?96cf:45)
at Generator.invoke [as _invoke] (runtime.js?96cf:271)
at Generator.prototype.<computed> [as next] (runtime.js?96cf:97)
at asyncGeneratorStep (asyncToGenerator.js?1da1:3)
at _next (asyncToGenerator.js?1da1:25)
at eval (asyncToGenerator.js?1da1:32)
client.js?06a0:77类型错误:无法读取未定义的属性“mounted”
在Auth.mounted(Auth.js?facc:112)
在Auth.setStrategy(Auth.js?facc:108)
在Auth.loginWith(Auth.js?facc:123)
在3$(登录.vue?f35c:175)
在tryCatch(runtime.js?96cf:45)
在Generator.invoke[as_invoke](runtime.js?96cf:271)
在发电机上。原型。[作为下一个](runtime.js?96cf:97)
在asyncGeneratorStep(asyncToGenerator.js?1da1:3)
at_next(asyncToGenerator.js?1da1:25)
评估时(asyncToGenerator.js?1da1:32)

如何在nuxt js中为两个不同的身份验证创建两个端点?提前谢谢你

我已经做出了不同的决定,让它发挥作用。终于成功了

 this.$axios.post('user/token/', {
              id : res.data.id,
              firstname: res.data.firstname,
              lastname : res.data.lastname,
              email: res.data.email
          })
          .then((resp) => {
            this.$auth.setToken('local', 'Bearer ' + resp.data.access)
            this.$axios.setHeader('Authorization', 'Bearer ' + resp.data.access)
            this.$auth.ctx.app.$axios.setHeader('Authorization', 'Bearer ' + resp.data.access)
          })
          .then(() => {
            this.$axios.get('user/me/')
            .then((resp) => { 
              this.$auth.setUser(resp.data); 
              this.$router.push('/') 
            })
          .catch(() => {
          console.log(err)
          })

让我简单地解释一下。我没有使用nuxt auth local,而是使用它的方法来获得与local auth login相同的结果。首先,我将数据发布到服务器以创建一个用户,然后使用其数据登录。简单明了。如果有人需要,我可以更深入地解释。

当我刷新页面或使用$auth发出任何请求时,它仍然不使用令牌。我不是用户,我终于明白了原因。非常感谢。你的回答保存了我的密码