Last active
February 17, 2017 10:30
-
-
Save drozdzynski/de1584e3e16ea27f51798924b7da18a8 to your computer and use it in GitHub Desktop.
VueJS v2 - v-model input default value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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