vue3+ts报错解决:无法找到模块“xxx.vue”的声明文件 xxx隐式拥有 “any“ 类型。

99 阅读1分钟

原因:typeScript无法识别.vue文件

解决方法:在vite-env.d.ts文件添加以下代码(没有这个文件的可自行创建一个.d.ts的声明文件)

  import { ComponentOptions } from 'vue'
  const componentOptions: ComponentOptions
  export default componentOptions
}

代码作用:告诉 TypeScript 所有 .vue 文件都应该被当作 Vue 组件来处理