that the object is not an array, and yes, it’s fine to pass objects as props. Just set the values in the data object of the parent components, i.e.
data() {
return {
attributes: {
placeholder: 'Whatever',
length: 42,
},
...
}
}
and tie it as your footing:
<field :attrs="attributes"></field>
To clarify - you can set objects / arrays, etc. directly in the template, vue template parser will then set the values in the corresponding details, i.e.
<field :attrs="[{ name: 'foo' }, { name: 'bar' }]"></field>
However, this is not best practice, as your templates will soon become messy, and it may be more difficult to determine where the data is installed. Instead, it is recommended to abstract this data with a parameter on the component and bind this parameter to prop - as described above.
source
share