Map*_*Dev 4 javascript jquery ecmascript-6 vuejs2
我在 Vue.js 2 中使用 bootstrap-date-picker。Bootstrap datepicker 不会更新模型。
但是,如果我使用以下脚本,则无法访问要使用的范围 this
loadFormProps() {
// init other stuff
$('#founding_date').change(function() {
this.founding_date = $(this).val();
});
}
Run Code Online (Sandbox Code Playgroud)
模态如下:
data() {
return {
founding_date: '01 - 01 - 2017',
}
};
Run Code Online (Sandbox Code Playgroud)
什么是最好的解决方案,因为我无法vm.$data工作,也无法this在函数内访问。
你必须在JS 块之前保存this一些其他的内部:varonchange
loadFormProps() {
// init other stuff
var that = this
$('#founding_date').change(function() {
that.founding_date = $(this).val();
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3840 次 |
| 最近记录: |