[Vuejs]-Do I need to explicitly declare all component properties (vue.js)?

1👍

You don’t need to declare all of them, you can use v-bind to bind an object of optional attributes. So, in your parent you can do:

<custom-input :optional-attrs="{placeholder: 'Type something!'}"></custom-input>

Then in your component simply add it as a prop:

 props: {
   optionalAttrs: {}
 }

And use v-bind on your input in your component:

<input type="text" class="form-control" v-bind="optionalAttrs">

Here’s the JSFiddle: https://jsfiddle.net/rww551og/

1👍

You have to declare all props which CAN BE USED, but you have to add REQUIRE: TRUE only on those which are required. That’s all.

Leave a comment