I'm trying to apply the plugin Select2
on a select
I charge it using VUE.JS (I do a v-for
on the% option select
)
If I do not apply the plugin, by doing v-model="modelo"
, I can use the variable ({{modelo}})
correctly.
But if I apply the plugin, VUE stop reading the v-model
and I can not use the databinding
.
I attach the JSFIDDLE:
Code:
var vm = new Vue({
el: "#divMain",
data: {
selected: 'A',
options: [
{ text: 'One', value: 'A' },
{ text: 'Two', value: 'B' },
{ text: 'Three', value: 'C' }
]
}
});
$('#miSelect').select2({
placeholder: 'Select an option'
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.0.1/vue.min.js"></script>
<link href="https://rawgit.com/select2/select2/master/dist/css/select2.min.css" rel="stylesheet"/>
<script src="https://rawgit.com/select2/select2/master/dist/js/select2.js"></script>
<div id="divMain">
<select id="miSelect" v-model="selected">
<option v-for="opt in options" v-bind:value="opt.value">
{{ opt.text }}
</option>
</select>
<span>Selected: {{ selected }}</span>
</div>