我在 Vue.js 2 中使用 bootstrap-date-picker。Bootstrap datepicker 不更新 model .
但是如果我使用下面的脚本,我无法访问作用域来使用this
loadFormProps() {
// init other stuff
$('#founding_date').change(function() {
this.founding_date = $(this).val();
});
}
模态如下:
data() {
return {
founding_date: '01 - 01 - 2017',
}
};
最好的解决方案是什么,因为我无法让 vm.$data
工作,而且我无法在函数内访问 this
。
最佳答案
你必须在 onchange
JS block 之前将 this
保存在其他一些 var
中:
loadFormProps() {
// init other stuff
var that = this
$('#founding_date').change(function() {
that.founding_date = $(this).val();
});
}
关于javascript - 从 jQuery onChange 使用 Vue 更新数据值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41804708/