[英]Vue 3 + TypeScript TS2614: Module '"*.vue"' has no exported member
[英]How to avoid TS2614 error when importing interfaces from Vue components
我在我的 Vue 組件腳本部分定義了一個接口,當我嘗試將它導入另一個 typescript 文件時,出現此錯誤:
TS2614: Module '"../pages/categories/alimentation/index.vue"' has no exported member 'BenefitDetails'. Did you mean to use 'import BenefitDetails from "../pages/categories/alimentation/index.vue"' instead
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
export interface BenefitDetails {
name: string
frequency: string
cost: number
icon: string
description: string
}
@Component
export default class MyComponent extends Vue {
// my props ...
mounted() {}
}
</script>
// Error in import below
import { BenefitDetails } from '~/pages/categories/alimentation/index.vue'
export function getBenefitFrequencyColor({ frequency }: BenefitDetails) {
switch (frequency) {
case 'Mensal':
return 'blue'
default:
return 'yellow'
}
}
我在這個問題中找到了 VSCode 的解決方案,但我正在使用 webstorm
更新:我不想將接口聲明移動到另一個文件
嘗試在專用 ts 文件中聲明 BenefitDetails 接口(即:benefitDetails.model.ts)
然后在需要的地方導入 BenefitDetails
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.