Answer the question
In order to leave comments, you need to log in
Why is vue watch not working?
I'm not sure what I'm doing right, but the task is such. There is an input, by clicking on which a calendar pops up - accordingly, you select a date, and it changes in the input. Initially, the date is - today. Implementation in vue. Calendar, it just so happens - jquery datepicker.
var today = moment().format('DD.MM.YYYY');
var app = new Vue({
el: '#wrapper',
data: {
theDate: today
},
watch: {
'theDate' : function(value) {
alert(value);
}
}
});
<input v-model="theDate" type="text" id="theDate">
$('#dateStart').datepicker({
autoClose: true,
onSelect: function() {
$('#dateStart').trigger('change');
}
});
$(document).on('change', '#theDate', function() {
alert('ok');
});
Answer the question
In order to leave comments, you need to log in
First, the event must be input, not change. Secondly, native event handlers (and vue obviously uses them) look askance at the events that jquery generates. So it
should be replaced with something like
UPD. A couple of examples of what this might look like: one using jquery-ui datepicker two using air-datepicker.
$('#dateStart').trigger('change');
this.dispatchEvent(new Event('input'));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question