I currently use Vue.JS 2.0 and I want to update the model off one Vue instance from an custom directive, but im looking a nice way to do it, this is because i trying to create a
This will do the trick:
// vnode (third argument is required).
bind: function (el, binding, vnode) {
$(el).datepicker({
onSelect: function (date) {
// Set value on the binding expression.
// Here we set the date (see last argument).
(function set(obj, str, val) {
str = str.split('.');
while (str.length > 1) {
obj = obj[str.shift()];
}
return obj[str.shift()] = val;
})(vnode.context, binding.expression, date);
}
});
},
Reference: https://stackoverflow.com/a/10934946/2938326