我正在使用带Vue.js的bootstrap-date-picker 2. 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
。
答案 0 :(得分:3)
您必须在this
JS块之前将var
保存在其他onchange
内:
loadFormProps() {
// init other stuff
var that = this
$('#founding_date').change(function() {
that.founding_date = $(this).val();
});
}