问题、导入文件有红色的波浪线,出现
解决办法:1、先在src目录下创建一个类型说明文件,如vueDeclaration.ts文件,在文件中写入以下代码
declare module '*.vue' {
import { DefineComponent } from 'vue';
const component: DefineComponent<{}, {}, any>;
export default component;
}
次代码主要是对vue导入的文件声明。
2、如果设置完成这个还是有会出现导入红色的波浪线,有可能是路径别名没有映射
在vite.config.ts中设置如下代码
export default defineConfig({
plugins: [
vue(),
vueJsx(),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)) //设置路径别名
}
}
})
但是还是会出现红色波浪线,需要在tsconfig.json文件中设置路径映射,代码如下
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"jsx": "preserve",
"strict": false,
"esModuleInterop": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"baseUrl": ".", //路径映射
"paths": {
"@/*": [
"src/*"
] //路径映射
}
},
如果还有会出现 import报错:Moudle … has no default export 需要将vscode插件中的vuter或者volar卸载换成 vue-Official插件,重启vscode即可