Reputation: 1130
I'm trying to pass props value in vue component to object as index like code below.
export default defineComponent({
props:{
pollId:{type: String}
},
data(){
return{
poll: polls[this.pollId]
}
}
})
But when I do this, I got error like these:
the compiler keeps assuming that my props are undefined
even I've specified it above.
is there a way to fix this? without sacrificing
Upvotes: 2
Views: 961
Reputation: 1130
It's actually as simple as adding required
property in props
export default defineComponent({
props:{
pollId:{required:true,type: String}
},
data(){
return{
poll: polls[this.pollId]
}
}
})
Upvotes: 1