Skip to content

Commit 6f7d219

Browse files
committedApr 30, 2024··
fix(runtime-vapor): set raw value for dynamic attrs
1 parent 098b6fc commit 6f7d219

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed
 

‎packages/runtime-vapor/src/componentAttrs.ts

+23-19
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,43 @@ export function patchAttrs(instance: ComponentInternalInstance) {
1212
propsOptions: [options],
1313
} = instance
1414

15+
if (!rawProps.length) return
1516
const keys = new Set<string>()
16-
if (rawProps.length)
17-
for (const props of Array.from(rawProps).reverse()) {
18-
if (isFunction(props)) {
19-
const resolved = props()
20-
for (const rawKey in resolved) {
21-
registerAttr(rawKey, () => resolved[rawKey])
22-
}
23-
} else {
24-
for (const rawKey in props) {
25-
registerAttr(rawKey, props[rawKey])
26-
}
17+
for (const props of Array.from(rawProps).reverse()) {
18+
if (isFunction(props)) {
19+
const resolved = props()
20+
for (const rawKey in resolved) {
21+
registerAttr(rawKey, resolved[rawKey])
22+
}
23+
} else {
24+
for (const rawKey in props) {
25+
registerAttr(rawKey, props[rawKey], true)
2726
}
2827
}
28+
}
2929

3030
for (const key in attrs) {
3131
if (!keys.has(key)) {
3232
delete attrs[key]
3333
}
3434
}
3535

36-
function registerAttr(key: string, getter: () => unknown) {
36+
function registerAttr(key: string, value: any, getter?: boolean) {
3737
if (
3838
(!options || !(camelize(key) in options)) &&
39-
!isEmitListener(instance.emitsOptions, key)
39+
!isEmitListener(instance.emitsOptions, key) &&
40+
!keys.has(key)
4041
) {
4142
keys.add(key)
42-
if (key in attrs) return
43-
Object.defineProperty(attrs, key, {
44-
get: getter,
45-
enumerable: true,
46-
configurable: true,
47-
})
43+
if (getter) {
44+
Object.defineProperty(attrs, key, {
45+
get: value,
46+
enumerable: true,
47+
configurable: true,
48+
})
49+
} else {
50+
attrs[key] = value
51+
}
4852
}
4953
}
5054
}

0 commit comments

Comments
 (0)
Please sign in to comment.