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

Function patchAttr

packages/runtime-dom/src/modules/attrs.ts:16–47  ·  view source on GitHub ↗
(
  el: Element,
  key: string,
  value: any,
  isSVG: boolean,
  instance?: ComponentInternalInstance | null,
  isBoolean: boolean = isSpecialBooleanAttr(key),
)

Source from the content-addressed store, hash-verified

14export const xlinkNS = 'http://www.w3.org/1999/xlink'
15
16export function patchAttr(
17 el: Element,
18 key: string,
19 value: any,
20 isSVG: boolean,
21 instance?: ComponentInternalInstance | null,
22 isBoolean: boolean = isSpecialBooleanAttr(key),
23): void {
24 if (isSVG && key.startsWith('xlink:')) {
25 if (value == null) {
26 el.removeAttributeNS(xlinkNS, key.slice(6, key.length))
27 } else {
28 el.setAttributeNS(xlinkNS, key, value)
29 }
30 } else {
31 if (__COMPAT__ && compatCoerceAttr(el, key, value, instance)) {
32 return
33 }
34
35 // note we are only checking boolean attributes that don't have a
36 // corresponding dom prop of the same name here.
37 if (value == null || (isBoolean && !includeBooleanAttr(value))) {
38 el.removeAttribute(key)
39 } else {
40 // attribute value is a string https://html.spec.whatwg.org/multipage/dom.html#attributes
41 el.setAttribute(
42 key,
43 isBoolean ? '' : isSymbol(value) ? String(value) : value,
44 )
45 }
46 }
47}
48
49// 2.x compat
50const isEnumeratedAttr = __COMPAT__

Callers 1

patchPropFunction · 0.90

Calls 4

includeBooleanAttrFunction · 0.90
isSymbolFunction · 0.90
compatCoerceAttrFunction · 0.85
StringInterface · 0.85

Tested by

no test coverage detected