【发布时间】:2021-09-18 16:18:07
【问题描述】:
如何解决以下打字稿错误?对于上下文,我使用的是 Vue 3 Composition API,我最终使用结果来指定默认选项值是否应为 <option ... selected v-if="!isMatch">。
Object is of type 'unknown'.
错误是突出显示第二个“选项”。
props:{
value: {
required: true,
type: String,
},
options: {
required: true,
type: Array,
},
}
setup(props){
const isMatch = () => props.options.find(option => {
return option['code'] === props.value
})
return { isMatch }
}
“选项”数据示例
[
{
"code": "CA",
"name": "Canada"
},
{
"code": "US",
"name": "United States"
}
]
【问题讨论】:
-
您能分享一下
props设置部分吗?从您在模板上的使用方式来看,我认为 RoToRa 是正确的,您可能想要使用Array.prototype.some而不是find。此处需要更多上下文。 -
@YomT。添加了道具。
-
将
computed用于isMatch -
@Lynx 谢谢,但不幸的是收到了同样的错误。
标签: javascript typescript vue.js vuejs3 vue-composition-api