mirror of
https://gitee.com/vuejs/vue.git
synced 2024-12-02 12:07:39 +08:00
better IE9 v-model support
This commit is contained in:
parent
aef93b3152
commit
5174bb2bd8
@ -1,5 +1,15 @@
|
||||
import { isAndroid, isIE9 } from '../util/env'
|
||||
|
||||
if (isIE9) {
|
||||
// http://www.matts411.com/post/internet-explorer-9-oninput/
|
||||
document.addEventListener('selectionchange', () => {
|
||||
const el = document.activeElement
|
||||
if (el && el.vmodel) {
|
||||
trigger(el)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export default {
|
||||
bind (el, value) {
|
||||
if (!isAndroid) {
|
||||
@ -7,8 +17,7 @@ export default {
|
||||
el.addEventListener('compositionend', onCompositionEnd)
|
||||
}
|
||||
if (isIE9) {
|
||||
el.addEventListener('cut', trigger)
|
||||
el.addEventListener('keyup', triggerOnDelOrBackspace)
|
||||
el.vmodel = true
|
||||
}
|
||||
},
|
||||
unbind (el) {
|
||||
@ -16,10 +25,6 @@ export default {
|
||||
el.removeEventListener('compositionstart', onCompositionStart)
|
||||
el.removeEventListener('compositionend', onCompositionEnd)
|
||||
}
|
||||
if (isIE9) {
|
||||
el.removeEventListener('cut', trigger)
|
||||
el.removeEventListener('keyup', triggerOnDelOrBackspace)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,17 +34,11 @@ function onCompositionStart (e) {
|
||||
|
||||
function onCompositionEnd (e) {
|
||||
e.target.composing = false
|
||||
trigger(e)
|
||||
trigger(e.target)
|
||||
}
|
||||
|
||||
function trigger (e) {
|
||||
const ev = document.createEvent('HTMLEvents')
|
||||
ev.initEvent('input', true, true)
|
||||
e.target.dispatchEvent(ev)
|
||||
}
|
||||
|
||||
function triggerOnDelOrBackspace (e) {
|
||||
if (e.keyCode === 46 || e.keyCode === 8) {
|
||||
trigger(e)
|
||||
}
|
||||
function trigger (el) {
|
||||
const e = document.createEvent('HTMLEvents')
|
||||
e.initEvent('input', true, true)
|
||||
el.dispatchEvent(e)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user