I do the same as in the following Vue 2 - How to set default type of array in props
Vue.component("Test-Attribute", {
props: {
attributes: {
type: Array,
required: false,
// Object or array defaults must be returned from
// a factory function
default: function () {
return [
{attributeName: 'One', multiselect: 0},
{attributeName: 'Two', multiselect: 1},
{attributeName: 'Three', multiselect: 0},
{attributeName: 'Four', multiselect: 1},
]
}
}
},
template: `
<div>
<component
v-for="(attribute,index) in attributes"
:key="index"
:name="attribute.attributeName"
:is="getAttributeType(attribute)"
>
{{ attribute.attributeName + ':' }}
</component>
</div>
`,
created() {
console.log(this.attributes)
},
methods: {
getAttributeType: function (attribute) {
return parseInt(attribute.multiselect) === 1 ? 'MultiAttribute' : 'SingleAttribute'
}
}
});
Updated the original question with the full component code, I I pass down a prop the component is rendered as expected