200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > vue3引入.vue文件以及.ts文件时提示找不到模块

vue3引入.vue文件以及.ts文件时提示找不到模块

时间:2023-12-06 03:28:47

相关推荐

vue3引入.vue文件以及.ts文件时提示找不到模块

1.找不到vue文件的,是因为ts无法解析我们的vue结尾的文件,所以需要在src目录下,

新建一个d.ts结尾的文件(可以叫env.d.ts)

然后里面这样写就可以

/// <reference types="vite/client" />declare module '*.vue' {import { DefineComponent } from 'vue';// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-typesconst component: DefineComponent<{}, {}, any>;export default component;}// 环境变量 TypeScript的智能提示interface ImportMetaEnv {VITE_APP_TITLE: string;VITE_APP_PORT: string;VITE_APP_BASE_API: string;}interface ImportMeta {readonly env: ImportMetaEnv;}

2,找不到ts文件就更正常了,我们需要在tsconfig.json里面进行配置(没有的话就新建一个,在根src同级的目录下面)。就直接复制就完事了,

{"compilerOptions": {"target": "esnext","module": "esnext","useDefineForClassFields": true,"moduleResolution": "node","strict": true,"jsx": "preserve","sourceMap": true,"skipLibCheck": true,"resolveJsonModule": true,"esModuleInterop": true,"lib": ["esnext", "dom"],"baseUrl": "./","paths": {"@": ["src"],"@/*": ["src/*"]}},"include": ["src/**/*.ts","src/**/*.d.ts","src/**/*.tsx","src/**/*.vue","*.ts"],"references": [{ "path": "./tsconfig.node.json" }]}

有的博主可能直接是在include里面加

"src/**/*.ts",

这样是一种情况,这样让我们多级选目录时不报错,

但是还是会有'.xxx.ts'这样简单的路径导入,所以我们就必须加

"*.ts"

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。