我正在尝试在 Vue 3 / Typescript 中导入 .vue 组件,但我不断收到此错误:
Cannot find module '@/components/Fields/IconButton' or its corresponding type declarations. Vetur(2307)
如果我将 .vue 组件导入为 @/components/Fields/IconButton.vue
它可以工作,但如果我将其导入为 @/components/Fields/IconButton
则它不起作用
我做错了什么?
我的tsconfig.json:
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"baseUrl": ".",
"types": [
"webpack-env",
"jest"
],
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
],
"exclude": [
"node_modules"
]
}
我的 shims-vue.d.ts 在 src/ 下:
/* eslint-disable */
declare module '*.vue' {
import type { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}
非常感谢。 :)