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

Function setChecked

packages/runtime-dom/src/directives/vModel.ts:165–188  ·  view source on GitHub ↗
(
  el: HTMLInputElement,
  { value, oldValue }: DirectiveBinding,
  vnode: VNode,
)

Source from the content-addressed store, hash-verified

163}
164
165function setChecked(
166 el: HTMLInputElement,
167 { value, oldValue }: DirectiveBinding,
168 vnode: VNode,
169) {
170 // store the v-model value on the element so it can be accessed by the
171 // change listener.
172 ;(el as any)._modelValue = value
173 let checked: boolean
174
175 if (isArray(value)) {
176 checked = looseIndexOf(value, vnode.props!.value) > -1
177 } else if (isSet(value)) {
178 checked = value.has(vnode.props!.value)
179 } else {
180 if (value === oldValue) return
181 checked = looseEqual(value, getCheckboxValue(el, true))
182 }
183
184 // Only update if the checked state has changed
185 if (el.checked !== checked) {
186 el.checked = checked
187 }
188}
189
190export const vModelRadio: ModelDirective<HTMLInputElement> = {
191 created(el, { value }, vnode) {

Callers 1

beforeUpdateFunction · 0.85

Calls 5

looseIndexOfFunction · 0.90
isSetFunction · 0.90
looseEqualFunction · 0.90
getCheckboxValueFunction · 0.85
hasMethod · 0.80

Tested by

no test coverage detected