Skip to content

Instantly share code, notes, and snippets.

@moreta
Created November 22, 2018 03:51
Show Gist options
  • Save moreta/b48fc8ac946932826be9a8d1fd673634 to your computer and use it in GitHub Desktop.
Save moreta/b48fc8ac946932826be9a8d1fd673634 to your computer and use it in GitHub Desktop.
vue 日本語入力 input model binding
// 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
}
})
@moreta
Copy link
Author

moreta commented Nov 22, 2018

usage

<input v-jp-model="searchText">

@moreta
Copy link
Author

moreta commented Feb 26, 2019

binding.valueは v-jp-model="ここのvalue"が渡される。
もし、formatted inputがほしい場合はこの方法は聞かない

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment