MCPcopy
hub / github.com/vuejs/core / created

Function created

packages/runtime-dom/src/directives/vModel.ts:60–82  ·  view source on GitHub ↗
(el, { modifiers: { lazy, trim, number } }, vnode)

Source from the content-addressed store, hash-verified

58 'trim' | 'number' | 'lazy'
59> = {
60 created(el, { modifiers: { lazy, trim, number } }, vnode) {
61 el[assignKey] = getModelAssigner(vnode)
62 const castToNumber =
63 number || (vnode.props && vnode.props.type === 'number')
64 addEventListener(el, lazy ? 'change' : 'input', e => {
65 if ((e.target as any).composing) return
66 el[assignKey](castValue(el.value, trim, castToNumber))
67 })
68 if (trim || castToNumber) {
69 addEventListener(el, 'change', () => {
70 el.value = castValue(el.value, trim, castToNumber)
71 })
72 }
73 if (!lazy) {
74 addEventListener(el, 'compositionstart', onCompositionStart)
75 addEventListener(el, 'compositionend', onCompositionEnd)
76 // Safari < 10.2 & UIWebView doesn't fire compositionend when
77 // switching focus before confirming composition choice
78 // this also fixes the issue where some browsers e.g. iOS Chrome
79 // fires "change" instead of "input" on autocomplete.
80 addEventListener(el, 'change', onCompositionEnd)
81 }
82 },
83 // set value on mounted so it's after min/max for type="range"
84 mounted(el, { value }) {
85 el.value = value == null ? '' : value

Callers

nothing calls this directly

Calls 12

addEventListenerFunction · 0.90
looseIndexOfFunction · 0.90
isSetFunction · 0.90
looseEqualFunction · 0.90
looseToNumberFunction · 0.90
nextTickFunction · 0.90
getModelAssignerFunction · 0.85
castValueFunction · 0.85
getValueFunction · 0.85
getCheckboxValueFunction · 0.85
callModelHookFunction · 0.85
mapMethod · 0.80

Tested by

no test coverage detected