【问题标题】:Vue3/TypeScript - Can not import interface bc. of missing export default?Vue3/TypeScript - 无法导入接口 bc。缺少出口默认值?
【发布时间】:2022-11-07 20:39:45
【问题描述】:

我写了一个我想在我的组件中使用的接口。但是,似乎我无法真正导入界面,也看不到原因。

这是重要的代码:

我在 src/types/Job.ts 中的界面

interface Job {
  name: string,
  salary: string,
  isPopular: boolean
}

export default Job

还有我的 App.vue 设置功能和导入:

<script lang="ts">
import { defineComponent, ref } from 'vue'
import Job from './types/Job'

export default defineComponent({
  setup() {
    const jobs = ref<Job[]>([
      {
        ...
      },
      {
        ...
      }
    ])

    return { jobs }
  }
})

作为一个错误,我得到以下信息:

Uncaught SyntaxError: The requested module '/src/types/Job.ts' does not provide an export named 'default' (at App.vue:55:8)

我真的很想知道为什么或缺少什么。任何人的想法?

【问题讨论】:

  • 试试import type Job from './types/Job'
  • 哦,那行得通,谢谢!我正在关注一个在导入之前没有添加“类型”的 youtube 教程,它在那里工作。真的很困惑,但谢谢!

标签: typescript vue.js vuejs3


【解决方案1】:

尝试在 import 关键字后添加 type

import type Job from './types/Job'

【讨论】:

    猜你喜欢
    • 2016-05-06
    • 2022-08-16
    • 1970-01-01
    • 2015-08-23
    • 1970-01-01
    • 2015-07-28
    • 2017-05-31
    • 2018-12-13
    • 2022-12-07
    相关资源
    最近更新 更多