参考文章传送门,src目录下面有一个shims-vue.d.ts(名字可以随便起,毕竟tsconfig会自动加载src下面的所有ts文件)
// 声明.vue模块
declare module '*.vue' {
import { defineComponent } from 'vue'
const component: ReturnType<typeof defineComponent>
export default component
}
// 声明.png模块 .jpg同理
declare module "*.png" {
const value: any;
export default value;
}
至于svg,通过上面的声明方式加载进来仍不能正常使用,webpack还要配置个svg-loader才行

本文介绍了如何在Vue项目中结合使用TypeScript,通过声明`*.vue`和`*.png`模块来增强类型检查。同时,针对SVG文件的处理,除了声明外,还需要配置webpack使用svg-loader以确保正常加载和使用。

1万+

被折叠的 条评论
为什么被折叠?



