vue3加ts出现 --找不到模块“@/views/HomeView.vue”或其相应的类型声明。

今天在尝试用vite+vue3+ts+pinia创建项目,结果刚上来就遇到这么一个问题,
在这里插入图片描述
屎壳郎它不咬人,他恶心人呀😒,身为强迫症的我受不了!!!
出现这个问题的原因大概就是:ts只支持导出导入模块,但是vue不是模块,我们需要申明一下vue是个模块,你ts可以导入,
问题解决方法:

  • 目录下有env.d.ts文件
在文件中加上
declare module '*.vue' {
   import type { DefineComponent } from 'vue'
   const component: DefineComponent<{}, {}, any>
   export default component
}
或者
declare module '*.vue' {
   import type { DefineComponent } from 'vue'
   const component: ComponentOptions | ComponentOptions['setup']
   export default component
}
  • 目录下没有就新建一个喽。
    有用麻烦点个小心心哦,拜了个拜。
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐