【问题标题】:Module '"*.vue"' has no exported member 'Hoge'. Did you mean to use 'import Meeting from "*.vue"' instead?ts(2614)模块 '"*.vue"' 没有导出的成员 'Hoge'。您的意思是改用“从“* .vue”导入会议吗?ts(2614)
【发布时间】:2022-01-21 05:11:02
【问题描述】:

夏天

我已经实现了 Vue.js/Nuxt.js 应用程序。
在应用程序中,我将 vue 文件导入到 typescript 文件中。

打字稿文件

import { Hoge } from '~/layouts/default.vue'

~/layouts/default.vue

<script lang="ts">
export interface Hoge{
  hoge: string
}
</script>

但我在 { Hoge } 上显示错误,说 Module '"*.vue"' has no exported member 'Hoge'. Did you mean to use 'import Meeting from "*.vue"' instead?ts(2614)

我想知道如何解决这个错误。

我尝试过的

我已经设置了index.d.ts

declare module '*.vue' {
  import Vue from 'vue'
  export default Vue
}

【问题讨论】:

    标签: typescript vue.js nuxt.js


    【解决方案1】:

    我不确定您为什么要尝试从 vue 文件中导入类型,但这是我的建议:

    创建文件/types/shared.ts 并在里面添加:

    export interface Hoge{
      hoge: string
    }
    

    你可以像这样导入这个接口:

    import { Hoge } from '~/types/shared'
    

    【讨论】:

      猜你喜欢
      • 2021-10-08
      • 2021-01-12
      • 2021-08-14
      • 2021-10-17
      • 1970-01-01
      • 2021-12-09
      • 2019-10-01
      • 2021-05-26
      • 2021-12-22
      相关资源
      最近更新 更多