0


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

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
}
  • 目录下没有就新建一个喽。 有用麻烦点个小心心哦,拜了个拜。

本文转载自: https://blog.csdn.net/weixin_46587302/article/details/126853866
版权归原作者 子恒吃西瓜 所有, 如有侵权,请联系我们删除。

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

还没有评论