[英]VueJS/Typescript - Cannot find module './components/Navigation' or its corresponding type declarations
When I create a script as typescript (lang="ts") I get an error stating当我将脚本创建为打字稿 (lang="ts") 时,我收到一条错误消息
"Cannot find module './components/Navigation' or its corresponding type declarations (Vetur 2307).".
“找不到模块‘./components/Navigation’或其相应的类型声明(Vetur 2307)。”。
I realized that this only happens when I set the lang as ts, which is what I need to build my Vue application.我意识到这只有在我将 lang 设置为 ts 时才会发生,这是我构建 Vue 应用程序所需要的。
app.vue应用程序
<template>
<Navigation />
</template>
<script lang="ts">
import Navigation from './components/Navigation'; // This is where I get the error message
export default {
name: 'app',
components: {
Navigation,
}
}
</script>
Navigation.vue导航.vue
<template>
<div id="nav">
<router-link to="/">Home</router-link>
<router-link to="/about">About</router-link>
<router-link to="/categories">Categories</router-link>
<router-link to="/random">Random</router-link>
</div>
<router-view />
</template>
<script lang="ts">
export default {
name: 'Navigation',
}
</script>
In the src
folder add the file shims-vue.d.ts
with the following content :在
src
文件夹中添加文件shims-vue.d.ts
,内容如下:
Vue 2 :视图 2:
declare module "*.vue" {
import Vue from 'vue'
export default Vue
}
Vue 3:视图 3:
declare module '*.vue' {
import type { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}
and import the component with its extension .vue
:并使用其扩展名
.vue
导入组件:
import Navigation from './components/Navigation.vue';
instead of :代替 :
import Navigation from './components/Navigation';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.