我目前使用Vue.JS 2.0,我想从一个自定义指令更新一个Vue实例的模型,但是我看起来很好的方法,这是因为我试图创建一个实现JQueryUI-Datepicker代码的自定义指令如下:
<input type="text" v-datepicker="app.date" readonly="readonly"/>
Vue.directive('datepicker', {
bind: function (el, binding) {
$(el).datepicker({
onSelect: function (date) {
//this is executed every time i choose an date from datepicker
//pop.app.date = date; //this work find but is not dynamic to parent and is very dirty
Vue.set(pop, binding.expression, date); //this should work but nop
}
});
},
update: function (el, binding) {
$(el).datepicker('setDate', binding.value);
}
});
var pop = new Vue({
el: '#popApp',
data: {
app: {
date: ''
}
} …Run Code Online (Sandbox Code Playgroud)