javascript - 从 jQuery onChange 使用 Vue 更新数据值

标签 javascript jquery ecmascript-6 vuejs2

我在 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/

相关文章:

javascript:函数在分配给变量时返回未定义的值

Jquery datepicker - 手动触发

jquery - Bootstrap 表单边框渐变

jquery - 从 Select2 ajax 调用获取 Form 中选定的数据

javascript - 如何遍历 react 状态变量数组并确定它是否有一个真值

ecmascript-6 - 在模板文字中使用 ES6 扩展语法

javascript - meteor 构建中的箭头功能导致 Heroku 部署崩溃

javascript - 在 mvc 4 razor 中逐一选中列表中的每个复选框后,如何调用 Ajax 函数

javascript - 将ckeditor中编辑的数据保存到html文件

javascript - 显示最后一个记录值,不是所有值都循环