C
C
Camaro672018-11-09 10:34:00
Vue.js
Camaro67, 2018-11-09 10:34:00

How to correctly bind v-model to a custom checkbox component?

Hello! Based on the documentation, the v-model binding in the checkbox and radio component should look something like this:

Vue.component('app-checkbox', {
    model: {
        prop: 'checked',
        event: 'change'
    },
    props: ['name', 'value', 'checked'],
    template: `
        <label>
            <input 
                type="checkbox" 
                :name="name" 
                :value="value" 
                :checked="checked" 
                @change="$emit('change', $event.target.checked)">
            <slot></slot>
        </label>
    `
});

But in this case, v-model works with boolean values, and the array can no longer be passed (it will be converted to a boolean value). What am I doing wrong?
UPD: Example for better understanding

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-11-09
@Camaro67

keep
UPD. Or, using your demo .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question