首页 > 解决方案 > 基于 Vue 3 Typescript 的项目中的类型问题

问题描述

我在 Vue 组件中使用了一个 v-for 循环,options其中type of Object应该迭代一个 Prop。

道具在单独的文件中声明。

请看以下附件:

Vue组件:

v-for 循环出错

道具在props.ts 中声明:

道具声明

注意:选项返回一个字符串对象,我将其用于复选框或单选按钮项目。

如何解决这种类型的问题?

标签: javascripttypescriptvue.jsvuejs3vue-props

解决方案


我通过使用返回对象的默认值和删除未定义的类型解决了这个问题。

options: {
   type: Object,
   required: true,
   describe: "Provide a collection of components to render in the group",
   default: function (): unknown {
     return {}
   },
},

注意:我不确定这是否是此类型问题的正确解决方案。


推荐阅读