kevsterdev
kevsterdev

Reputation: 45

VUE emit from child to parent v-model

child

template: `
    <li v-for="option in listaOptiuni" :key="option.id">
        <input @change="updateSelectAllToateOptiunile(); sendListaToateOptiunile()" v-model="listaToateOptiunile" :value="option" :id="option" type="checkbox" class="uk-checkbox">
        <label :for="option">{{ option.denumire }}</label>
    </li>
`

data: function() {
    return {
        listaToateOptiunile: []
    }
}

parent

<my-component v-model="myList"></my-component>

How I send values of listaToateOptiunile from child direct into v-model myList from parent?

Upvotes: 0

Views: 404

Answers (1)

Moritz Ringler
Moritz Ringler

Reputation: 15816

By emitting the event v-model listens to.

In Vue2, that's input:

<input @change="updateSelectAllToateOptiunile(); sendListaToateOptiunile(), $emit('input', listaToateOptiunile)" v-model="listaToateOptiunile" :value="option" :id="option" type="checkbox" class="uk-checkbox">

In Vue 3, that's update:modelValue:

<input @change="updateSelectAllToateOptiunile(); sendListaToateOptiunile(), $emit('update:modelValue', listaToateOptiunile)" v-model="listaToateOptiunile" :value="option" :id="option" type="checkbox" class="uk-checkbox">

Upvotes: 1

Related Questions