首页 > Web开发 > 详细

nuxt.js 使用 Typescript 在 VSCode 报错: File 'xxx/components/Logo.vue' is not a module. Vetur(2306)

时间:2020-06-16 17:13:27      阅读:374      评论:0      收藏:0      [点我收藏+]

nuxt.js 生成的默认文件 components/Logo.vue 源码大概如下:

 1 <template>
 2   <svg
 3     class="NuxtLogo"
 4   >
 5   </svg>
 6 </template>
 7 <style>
 8 .NuxtLogo {
 9   margin: auto;
10 }
11 </style>

在 page/index.vue 文件中引入 `import Logo from ‘~/components/Logo.vue‘;` 会报错:`File ‘xxx/components/Logo.vue‘ is not a module. Vetur(2306)`。

typescript 提示新增 vue-shims.d.ts ( https://github.com/Microsoft/TypeScript-Vue-Starter#single-file-components ),试过还是不行。

github issue 翻了一下,最后找到这个:https://github.com/vuejs/vetur/issues/1709

给 components/Logo.vue 添加 export 即可:

 1 <template>
 2   <svg
 3     class="NuxtLogo"
 4   >
 5   </svg>
 6 </template>
 7 <style>
 8 .NuxtLogo {
 9   margin: auto;
10 }
11 </style>
12 <script lang="ts">
13 import Vue from ‘vue‘;
14 
15 export default Vue.extend({
16   name: ‘LOGO‘,
17 });
18 </script>

添加之后,还需关闭重启 VSCode !

nuxt.js 使用 Typescript 在 VSCode 报错: File 'xxx/components/Logo.vue' is not a module. Vetur(2306)

原文:https://www.cnblogs.com/linx/p/13141283.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!