Level 18
The issue I believe here is Select2 creates it's own DOM elements and doesn't trigger Vu'e reactivity system when values change. When Select2 updates, Vue doesn't know about it, so v-model doesn't sync.
Why not use a Vue-compatible alternative like vue-select like so:
<v-select
v-model="form.category"
:options="categories"
label="title"
:reduce="category => category.id"
placeholder="Select Category"
/>
If you need to use Select2, here's a way to do the manual sync:
nextTick(() => {
$('.category-dropdown').select2().on('select2:select', function (e) {
// Manually update the form value
form.category = e.target.value;
});
});
// Watch for programmatic changes to update Select2
watch(() => form.category, (newVal) => {
$('.category-dropdown').val(newVal).trigger('change.select2');
});