javascript - 基于 Vue 3 Typescript 的项目中的类型问题
问题描述
我在 Vue 组件中使用了一个 v-for 循环,options
其中type of Object
应该迭代一个 Prop。
道具在单独的文件中声明。
请看以下附件:
Vue组件:
道具在props.ts 中声明:
注意:选项返回一个字符串对象,我将其用于复选框或单选按钮项目。
如何解决这种类型的问题?
解决方案
我通过使用返回对象的默认值和删除未定义的类型解决了这个问题。
options: {
type: Object,
required: true,
describe: "Provide a collection of components to render in the group",
default: function (): unknown {
return {}
},
},
注意:我不确定这是否是此类型问题的正确解决方案。