Typescript NUXT -PHPSTORM- VUE SFC模板中缺少定义

发布于 2025-02-13 16:52:02 字数 3871 浏览 0 评论 0 原文

目前,我正在研究一个小型口袋妖怪API项目,以学习VUE2/Typescript/NUXT。它以Plain Vue App的速度开始,集成 Vue-Class-Component ,然后用Typescript(Nuxt-typescript模块)迁移到NUXT。

课程组件内部一切正常:例如,我获得了 this的类型提示。 ;模板> 标记我的phpstorm不再识别它们。

另一方面,我获得了组件属性的代码完成以及一些默认的VUE方法。

这是我的tsconfig.json和package.json:

{
  "compilerOptions": {
    "target": "ES2018",
    "module": "ESNext",
    "moduleResolution": "Node",
    "lib": [
      "ESNext",
      "ESNext.AsyncIterable",
      "DOM"
    ],
    "jsx": "preserve",
    "emitDecoratorMetadata": true,
    "esModuleInterop": true,
    "allowJs": true,
    "sourceMap": true,
    "strict": true,
    "noEmit": true,
    "experimentalDecorators": true,
    "baseUrl": ".",
    "paths": {
      "~/*": [
        "./*"
      ],
      "@/*": [
        "./*"
      ]
    },
    "types": [
      "@types/node",
      "@types/lodash",

      "@nuxt/types",
      "@nuxt/i18n",

      "@nuxtjs/axios",
      "@nuxtjs/auth-next",
      "@nuxtjs/sentry",
      "@nuxtjs/vuetify",
      "@nuxtjs/i18n",
      "@nuxtjs/proxy",

      "vuetify",
    ]
  },
  "exclude": [
    "node_modules",
    ".nuxt",
    "dist"
  ]
}

{
  "name": "pokemon-vue",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "nuxt start",
    "generate": "nuxt generate",
    "lint:js": "eslint --ext \".js,.ts,.vue\" --ignore-path .gitignore .",
    "lint:prettier": "prettier --check .",
    "lint": "npm run lint:js && npm run lint:prettier",
    "lintfix": "prettier --write --list-different . && npm run lint:js -- --fix"
  },
  "dependencies": {
    "@nuxt/typescript-runtime": "^2.1.0",
    "@nuxt/webpack": "^2.15.8",
    "@nuxtjs/axios": "^5.13.6",
    "@nuxtjs/i18n": "^7.2.2",
    "@nuxtjs/pwa": "^3.3.5",
    "core-js": "^3.19.3",
    "lodash": "^4.17.21",
    "nuxt": "^2.15.8",
    "nuxt-property-decorator": "^2.9.1",
    "nuxt-typed-vuex": "^0.3.1",
    "pokedex-promise-v2": "^4.0.0",
    "vue": "^2.6.14",
    "vue-router": "^3.5.4",
    "vue-server-renderer": "^2.6.14",
    "vue-template-compiler": "^2.6.14",
    "vuetify": "^2.6.1"
  },
  "devDependencies": {
    "@babel/eslint-parser": "^7.16.3",
    "@nuxt/types": "^2.15.8",
    "@nuxt/typescript-build": "^2.1.0",
    "@nuxtjs/eslint-config-typescript": "^8.0.0",
    "@nuxtjs/eslint-module": "^3.0.2",
    "@nuxtjs/vuetify": "^1.12.3",
    "@typescript-eslint/eslint-plugin": "^5.28.0",
    "@typescript-eslint/parser": "^5.28.0",
    "eslint": "^8.15.0",
    "eslint-config-prettier": "^8.5.0",
    "eslint-plugin-nuxt": "^3.1.0",
    "eslint-plugin-prettier": "^4.0.0",
    "eslint-plugin-vue": "^8.2.0",
    "prettier": "^2.5.1",
    "vue-eslint-parser": "^9.0.2",
    "@types/lodash": "^4.14.182"
  }
}

我遵循 typescript.nuxtjs ,即使将其添加到我的/types/index.d.d.d.ts

import { CreateElement, VNode } from 'vue'

import 'vue-class-component/hooks'

declare module 'vue/types/vue' {
  // Augment component instance type
  interface Vue {
    render?(createElement: CreateElement): VNode
  }
}
// https://typescript.nuxtjs.org/guide/setup/#configuration
declare module '*.vue' {
  import Vue from 'vue'
  export default Vue
}

删除 .idea 文件夹和“重新集结”该项目对phpstorm也无济于事:(

现在我是出于想法如何解决此问题,我为任何提示感到非常高兴。

Currently I am working on a small Pokemon API Project to learn the Vue2/TypeScript/Nuxt. It started as plain Vue app, integrated vue-class-component and migrated now to Nuxt with TypeScript (nuxt-typescript module).

Everything works fine inside the class component: e.g. I get type hinting for this.$t() or $fetchState but when I try to use these inside the <template> tag my PhpStorm doesn't recognize them anymore.

On the other hand, I get code completion for component properties as well as some default Vue methods.

enter image description here

enter image description here

Here is my tsconfig.json and package.json:

{
  "compilerOptions": {
    "target": "ES2018",
    "module": "ESNext",
    "moduleResolution": "Node",
    "lib": [
      "ESNext",
      "ESNext.AsyncIterable",
      "DOM"
    ],
    "jsx": "preserve",
    "emitDecoratorMetadata": true,
    "esModuleInterop": true,
    "allowJs": true,
    "sourceMap": true,
    "strict": true,
    "noEmit": true,
    "experimentalDecorators": true,
    "baseUrl": ".",
    "paths": {
      "~/*": [
        "./*"
      ],
      "@/*": [
        "./*"
      ]
    },
    "types": [
      "@types/node",
      "@types/lodash",

      "@nuxt/types",
      "@nuxt/i18n",

      "@nuxtjs/axios",
      "@nuxtjs/auth-next",
      "@nuxtjs/sentry",
      "@nuxtjs/vuetify",
      "@nuxtjs/i18n",
      "@nuxtjs/proxy",

      "vuetify",
    ]
  },
  "exclude": [
    "node_modules",
    ".nuxt",
    "dist"
  ]
}

{
  "name": "pokemon-vue",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "nuxt start",
    "generate": "nuxt generate",
    "lint:js": "eslint --ext \".js,.ts,.vue\" --ignore-path .gitignore .",
    "lint:prettier": "prettier --check .",
    "lint": "npm run lint:js && npm run lint:prettier",
    "lintfix": "prettier --write --list-different . && npm run lint:js -- --fix"
  },
  "dependencies": {
    "@nuxt/typescript-runtime": "^2.1.0",
    "@nuxt/webpack": "^2.15.8",
    "@nuxtjs/axios": "^5.13.6",
    "@nuxtjs/i18n": "^7.2.2",
    "@nuxtjs/pwa": "^3.3.5",
    "core-js": "^3.19.3",
    "lodash": "^4.17.21",
    "nuxt": "^2.15.8",
    "nuxt-property-decorator": "^2.9.1",
    "nuxt-typed-vuex": "^0.3.1",
    "pokedex-promise-v2": "^4.0.0",
    "vue": "^2.6.14",
    "vue-router": "^3.5.4",
    "vue-server-renderer": "^2.6.14",
    "vue-template-compiler": "^2.6.14",
    "vuetify": "^2.6.1"
  },
  "devDependencies": {
    "@babel/eslint-parser": "^7.16.3",
    "@nuxt/types": "^2.15.8",
    "@nuxt/typescript-build": "^2.1.0",
    "@nuxtjs/eslint-config-typescript": "^8.0.0",
    "@nuxtjs/eslint-module": "^3.0.2",
    "@nuxtjs/vuetify": "^1.12.3",
    "@typescript-eslint/eslint-plugin": "^5.28.0",
    "@typescript-eslint/parser": "^5.28.0",
    "eslint": "^8.15.0",
    "eslint-config-prettier": "^8.5.0",
    "eslint-plugin-nuxt": "^3.1.0",
    "eslint-plugin-prettier": "^4.0.0",
    "eslint-plugin-vue": "^8.2.0",
    "prettier": "^2.5.1",
    "vue-eslint-parser": "^9.0.2",
    "@types/lodash": "^4.14.182"
  }
}

I followed all the steps in typescript.nuxtjs, even with adding this to my /types/index.d.ts

import { CreateElement, VNode } from 'vue'

import 'vue-class-component/hooks'

declare module 'vue/types/vue' {
  // Augment component instance type
  interface Vue {
    render?(createElement: CreateElement): VNode
  }
}
// https://typescript.nuxtjs.org/guide/setup/#configuration
declare module '*.vue' {
  import Vue from 'vue'
  export default Vue
}

Deleting the .idea folder and "reimporting" the project to PhpStorm also didn't help :(

Now I am out of ideas how to fix this issue and I am very happy for any tips.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初与友歌 2025-02-20 16:52:02

这是IDE中的一个错误,请关注 Web-56522 用于更新

It's a bug in the IDE, please follow WEB-56522 for updates

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文