Created
November 22, 2018 03:51
-
-
Save moreta/b48fc8ac946932826be9a8d1fd673634 to your computer and use it in GitHub Desktop.
vue 日本語入力 input model binding
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
// japanese input | |
var vCompositionModelUpdate = function (el, binding, vnode) { | |
vnode.context[binding.expression] = el.value | |
} | |
Vue.directive('jp-model', { | |
bind: function (el, binding, vnode) { | |
el.value = binding.value | |
el.addEventListener('keyup', vCompositionModelUpdate.bind(this, el, binding, vnode)) | |
el.addEventListener('compositionend', vCompositionModelUpdate.bind(this, el, binding, vnode)) | |
}, | |
update: function (el, binding) { | |
el.value = binding.value | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
binding.valueは v-jp-model="ここのvalue"が渡される。
もし、formatted inputがほしい場合はこの方法は聞かない