Adding vee-validate / HTML attributes to input element in slot Adding vee-validate / HTML attributes to input element in slot vue.js vue.js

Adding vee-validate / HTML attributes to input element in slot


How about scoped slots (Vue 2.5.0+)?

<!-- form-group.vue --><template>  <div>    <label />    <slot v-bind="$props" />    <span />  </div></template>

Above, all the props of <form-group> is bound to the slot using v-bind. You may want to specify certain fields only: <slot :id="name" :data-vv-name="name" />

<form-group name="age">  <input type="number" slot-scope="slotProps" v-bind="slotProps" /></form-group>

Here, the <input> can access the slot props by using slot-scope, giving it a name (here slotProps). slotProps will contain all the props of <slot> as defined in form-group.vue.

Some more examples:

<form-group name="language">  <input type="text" slot-scope="sp" v-bind="sp" /></form-group><form-group name="hello" value="friend">  <span slot-scope="sp">    {{ sp.name }}: {{ sp.value }}  </span></form-group>


As said in the comments, it is not possible to pass the props from the to the content of the slot, which is your <input>.

As this is quite complex case, it would require the use of a Render Function, which sends the custom attributes into the new tag while applying a set of default attributes.

I have done a proof of concept here: https://codepen.io/anon/pen/Ozadop?editors=1010