模块没有导出成员 Vue3

时间:2021-04-13 15:31:38

标签: typescript vue.js vue-component

我需要一些 Vue 组件方面的帮助。

我收到此错误:

Failed to compile.

src/components/Btn/Btn.vue:11:14
TS2305: Module '"../../typings/button-type"' has no exported member 'ButtonType'.
     9 |     import { defineComponent, computed } from '@vue/runtime-core';
  > 11 |     import { ButtonType } from '@/typings/button-type';
       |              ^^^^^^^^^^
    12 | // components
    13 |
    14 |     export default defineComponent({

我正在尝试在一个单独的文件中在 Ts 中创建我自己的类型并将其导入我的组件中。

类型:

export namespace ButtonType {

export type Button = {
size: Size;
type: Type;
 }
}

type Size = 'sm' | 'md' | 'lg';
type Type = 'primary' | 'accent' | 'subtle';

在我的组件中,我有以下内容:

   import { ButtonType } from '@/typings/button-type';
// components

export default defineComponent({
    name: 'Btn',
    components: {},
    props: {
        size: {
            default: 'md',
        } as ButtonType.Button.size,
        type: {
            default: 'primary',
        } as ButtonType.Button.type,
    }

我试过 ButtonType.Button['size'] 但都没有奏效。

我有一些计算数据等,但与案例无关。主要想法是创建一个类型,以便在为按钮组件设置错误的大小或类型时识别错误。

知道发生了什么吗?

1 个答案:

答案 0 :(得分:1)

Vue 使用 expect(questionDropdown).toHaveAttribute("data-testid", "test-id"); 作为 prop 类型

ques = []
substr = "my SearchedKey".lower()
with open ('pr.txt', 'rt', encoding="utf-8") as myfile:
    for line in myfile:
        if line.lower().find(substr) != -1:
            ques.append(line.rstrip('\n'))
for answ in ques:
    print(answ)
相关问题