我正在尝试将 vue 组件中的 props 值作为索引传递给对象,就像下面的代码一样。
export default defineComponent({
props:{
pollId:{type: String}
},
data(){
return{
poll: polls[this.pollId]
}
}
})
编译器一直假设我的 props 是 undefined
,即使我在上面指定了它。
有没有办法解决这个问题?不牺牲
答案 0 :(得分:0)
其实就像在 props 中添加 required
属性一样简单
export default defineComponent({
props:{
pollId:{required:true,type: String}
},
data(){
return{
poll: polls[this.pollId]
}
}
})