Skip to content

Commit e32da91

Browse files
xanfyyx990803
authored andcommitted
fix(runtime-core): support object syntax for class (#215)
1 parent 5f28708 commit e32da91

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

packages/runtime-core/src/vnode.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import {
44
isString,
55
isObject,
66
EMPTY_ARR,
7-
extend,
8-
PatchFlags
7+
extend
98
} from '@vue/shared'
109
import {
1110
ComponentInternalInstance,
@@ -146,9 +145,7 @@ export function createVNode(
146145
if (isReactive(props) || SetupProxySymbol in props) {
147146
props = extend({}, props)
148147
}
149-
// class normalization only needed if the vnode isn't generated by
150-
// compiler-optimized code
151-
if (props.class != null && !(patchFlag & PatchFlags.CLASS)) {
148+
if (props.class != null) {
152149
props.class = normalizeClass(props.class)
153150
}
154151
let { style } = props

packages/vue/__tests__/index.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,19 @@ it('should support on-the-fly template compilation', () => {
1313
createApp().mount(App, container)
1414
expect(container.innerHTML).toBe(`0`)
1515
})
16+
17+
it('should correctly normalize class with on-the-fly template compilation', () => {
18+
const container = document.createElement('div')
19+
const App = {
20+
template: `<div :class="{ test: demoValue, test2: !demoValue }"></div>`,
21+
data() {
22+
return {
23+
demoValue: true
24+
}
25+
}
26+
}
27+
createApp().mount(App, container)
28+
const classes = container.firstElementChild!.classList
29+
expect(classes.contains('test')).toBe(true)
30+
expect(classes.contains('test2')).toBe(false)
31+
})

0 commit comments

Comments
 (0)