[Vuejs]-Vue pass v-on to subelement inside component

0👍

All the listeners will be attached to the root element. This is the default behaviour. To change this you can make use of $listeners option.

So to make it possible attach the listeners to the select element as follows:

<select v-on="$listeners" ref="selectField">
  <option v-for="item in list">{{item.name}}</option>
</select>

Now you can attach event listeners directly on your custom select component

<my-select v-on:change="doSomething"></my-select>

For more info check out – Building fully transparent wrapper components

Leave a comment