小编dmo*_*iba的帖子

Vue 中的 DefineProps 属性的复杂类型

在我的代码中,我已经(或希望)在某些时候使用复杂的 prop 类型。下面是我想到的示例:

enum Country {
  [...]
}

interface IPerson {
  firstname: string;
  lastname: string;

}

interface IAddress {
  street: string;
  houseNo: string;
  city: string;
  postalCode: string;
  country: number;
}

interface ITestComponentProps {
  person: IPerson;
  addresses: Array<IAddress>;
}
Run Code Online (Sandbox Code Playgroud)

那么我想用这一切来实现的TestComponent.vue是:

[...]
const props = defineProps<ITestComponentProps>();
[...]
Run Code Online (Sandbox Code Playgroud)

我现在期望的是某种错误消息或任何告诉我在尝试如下操作时没有提供正确结构的道具的信息:

[...]
<TestComponent :props="'foo'" />
[...]
Run Code Online (Sandbox Code Playgroud)

Vue 的文档中有如下说明:

目前不支持复杂类型和从其他文件导入类型。将来有可能支持类型导入。


有谁知道是否有解决方法来获得所需的行为或何时支持复杂类型?

typescript vue.js vuejs3 vue-composition-api vue-script-setup

3
推荐指数
1
解决办法
3855
查看次数