Javascript 使用Vue从jQuery onChange更新数据值
我在Vue.js 2中使用引导日期选择器。引导日期选择器不会更新 但是如果我使用以下脚本,我无法访问要使用的范围Javascript 使用Vue从jQuery onChange更新数据值,javascript,jquery,ecmascript-6,vuejs2,Javascript,Jquery,Ecmascript 6,Vuejs2,我在Vue.js 2中使用引导日期选择器。引导日期选择器不会更新 但是如果我使用以下脚本,我无法访问要使用的范围this loadFormProps() { // init other stuff $('#founding_date').change(function() { this.founding_date = $(this).val(); }); } 模式如下: data() { return { founding_date: '01 - 01 - 2017', }
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块之前将this
保存在其他var
中:
loadFormProps() {
// init other stuff
var that = this
$('#founding_date').change(function() {
that.founding_date = $(this).val();
});
}
在
change
回调函数中有两个this
。此无法访问哪个?控制台错误消息是什么?第一个这个应该指什么?有那么简单吗?谢谢你,先生!