如何解决vue3.0+typescript项目提示找不到模块“./App.vue”或其相应的类型声明?

ppylox
·9/15/2022·8 阅读

大家好我是图恩,今天在项目中遇到了这个问题,出现这个提示的原因在于typescript 只能理解 .ts 文件,无法理解 .vue文件,因此需要给.vue文件加上类型说明文件。

通过vue3.0的脚手架生成的项目在项目的根目录有一个env.d.ts的文件,默认情况下这个文件没有内容,我们可以将以下代码放入这个文件就可解决这个问题:

declare module '*.vue' {\n  import type { DefineComponent } from 'vue'\n  const component: DefineComponent<{}, {}, any>\n  export default component\n}

评论 (0)

暂无评论,来写第一条吧