vue3+ts报错:Cannot find module '@/views/Home/index.vue' or its corresponding type declarations.

技术 · 5 天前 · 访问: 18 次

方式一:

在使用 vue3+typescript 添加路由引入路径的时候报错:

Snipaste_2024-11-17_17-11-36.png

vite-env.d.ts 中添加:

declare module "*.vue" {
    import { DefineComponent } from "vue";
    const component: DefineComponent<{}, {}, any>;
    export default component;
}

通过以上方式可以取消报错爆红,但是当点击路径的时候跳转地址不正确。

方式二:

tsconfig.jsdon 中添加配置:

"compilerOptions": {
  "baseUrl": "./",  
  "paths": {
    "@/*": ["./src/*"]  
  }
}
前端 报错处理 报错问题处理 typescript vue3
icon_mrgreen.gificon_neutral.gificon_twisted.gificon_arrow.gificon_eek.gificon_smile.gificon_confused.gificon_cool.gificon_evil.gificon_biggrin.gificon_idea.gificon_redface.gificon_razz.gificon_rolleyes.gificon_wink.gificon_cry.gificon_surprised.gificon_lol.gificon_mad.gificon_sad.gificon_exclaim.gificon_question.gif
Theme Jasmine by Kent Liao