I am encountering issues when trying to access the props value (an array) in my composition API setup. The component I have is called DropDown, and I am passing it an array of objects. Here's what I need to achieve:
export default {
emits: ['update:modelValue'],
props: {
items: {
type: Array,
// required: true
},
modelValue: {
type: [String, Number, Boolean],
required: true
}
},
setup({modelValue, props} : any, {emit} : any ) {
let is_active = ref(false);
let selected = ref({
label: props.items[0].label,
icon: props.items[0].icon,
class: props.items[0].class
});
As you can see, I am using let selected
to store the first object from the items array, but it doesn't seem to be working. I can display the items on my template without any issues, but facing problems in the setup.
Any suggestions on how to resolve this?
By the way, the recommended practice is to use something like
let selected = reactive(props.items[0])
, but even that approach is not providing the desired outcome.