Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript NuxtJS身份验证错误,属性不为';不存在_Typescript_Nuxt.js - Fatal编程技术网

Typescript NuxtJS身份验证错误,属性不为';不存在

Typescript NuxtJS身份验证错误,属性不为';不存在,typescript,nuxt.js,Typescript,Nuxt.js,我刚刚在我的项目上安装了@nuxtjs/auth I get属性“$auth”在类型“AuthLoginPage”上不存在类 方法登录到登录类页面 My numxt.config.ts 我不可能使用NuxtJS Auth 您有什么想法吗?当您使用NuxtJs将Typescript添加到vueJs项目时,会导致此问题 此类型警告的解决方案发布在define types DefiniteTyped/DefiniteTyped的官方网站上 您需要在根项目类型/index.d.ts中创建一个文件并添加此

我刚刚在我的项目上安装了@nuxtjs/auth

I get
属性“$auth”在类型“AuthLoginPage”上不存在

方法登录到登录类页面 My numxt.config.ts 我不可能使用NuxtJS Auth


您有什么想法吗?

当您使用NuxtJs将Typescript添加到vueJs项目时,会导致此问题

此类型警告的解决方案发布在define types DefiniteTyped/DefiniteTyped的官方网站上

  • 您需要在根项目类型/index.d.ts中创建一个文件并添加此代码
  • 
    接下来,您的警告将消失

    这是解决警告的指南


    埃德温·伦顿·卡迪维德的答案是可行的,但这不是正确的方法

    我写了最初的打字,我刚刚提交了另一份PR,直接将打字与nuxt auth捆绑在一起:

    @nuxtjs/auth
    v5(在typescript中重新写入模块)开始合并PR之后,您所要做的就是将
    @nuxtjs/auth
    添加到tsconfig.json中的
    类型
    数组中

        "types": [
          "@nuxt/types", 
          "@types/nuxtjs__auth" // Add this line
        ]
    

    目前,在PR合并之前,请继续运行
    npm安装--保存dev@types/nuxtjs\uuu auth

    然后将
    @types/nuxtjs\uuuu auth
    添加到
    tsconfig.json中的
    types
    数组中


    你把它添加到nuxt配置了吗?如果是,请出示您的config@Aldarund是的,我添加了nuxt.config.ts auth-config插件。您是否将其添加到nuxt-config的modules部分,您只显示了部分nuxt-config。。。?你叫它什么名字?用什么方法?@Aldarund抱歉,我忘了完全添加配置:)我更新了第一条消息。你有什么想法吗?在codesandbox上创建一个repo,很难说不需要Itagely等待合并PR但还没有更新:(它被合并了,现在只是另一个PR的一部分:>实际上是这个:合并了但还没有发布。所以我求助于这个。谢谢我在
    中间件:(context)=>{context.$auth}中使用时仍然能得到它
    类型“Context”上不存在属性“$auth”
    modules: [
        // Doc: https://axios.nuxtjs.org/usage
        '@nuxtjs/axios',
        '@nuxtjs/auth',
        '@nuxtjs/pwa',
      ],
    ...
    auth: {
        strategies: {
          local: {
            endpoints: {
              login: {
                url: 'http://127.0.0.1:3001/users/login',
                method: 'post',
                propertyName: 'token'
              },
              logout: {
                url: 'http://127.0.0.1:3001/users/logout',
                method: 'post'
              },
              user: {
                url: 'http://127.0.0.1:3001/users/me',
                method: 'get',
                propertyName: 'user'
              }
            },
            // tokenRequired: true,
            // tokenType: 'bearer'
          }
        }
    
        "types": [
          "@nuxt/types", 
          "@nuxtjs/auth" // Add this line
        ]
    
    
        "types": [
          "@nuxt/types", 
          "@types/nuxtjs__auth" // Add this line
        ]