Skip to content

Instantly share code, notes, and snippets.

@drozdzynski
Last active February 17, 2017 10:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drozdzynski/de1584e3e16ea27f51798924b7da18a8 to your computer and use it in GitHub Desktop.
Save drozdzynski/de1584e3e16ea27f51798924b7da18a8 to your computer and use it in GitHub Desktop.
VueJS v2 - v-model input default value
export default {
install(Vue, options) {
Vue.directive('set-value', {
bind (el, binding, vnode, oldVnode) {
var model = vnode.data.directives.find(dir => dir.rawName === 'v-model');
if (!model || !model.expression) {
console.error('[vue-set-value warn] The element does not have v-model');
return;
}
vnode.context[model.expression] = binding.value;
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment