mirror of https://github.com/vuejs/core.git
fix(runtime-dom): v-bind style should clear previous css string value (#10373)
close #10352
This commit is contained in:
parent
76c9c742e9
commit
e2d323538e
|
@ -158,4 +158,13 @@ describe(`runtime-dom: style patching`, () => {
|
||||||
)
|
)
|
||||||
expect(el.style.display).toBe('flex')
|
expect(el.style.display).toBe('flex')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should clear previous css string value', () => {
|
||||||
|
const el = document.createElement('div')
|
||||||
|
patchProp(el, 'style', {}, 'color:red')
|
||||||
|
expect(el.style.cssText.replace(/\s/g, '')).toBe('color:red;')
|
||||||
|
|
||||||
|
patchProp(el, 'style', 'color:red', { fontSize: '12px' })
|
||||||
|
expect(el.style.cssText.replace(/\s/g, '')).toBe('font-size:12px;')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -13,10 +13,19 @@ export function patchStyle(el: Element, prev: Style, next: Style) {
|
||||||
const currentDisplay = style.display
|
const currentDisplay = style.display
|
||||||
let hasControlledDisplay = false
|
let hasControlledDisplay = false
|
||||||
if (next && !isCssString) {
|
if (next && !isCssString) {
|
||||||
if (prev && !isString(prev)) {
|
if (prev) {
|
||||||
for (const key in prev) {
|
if (!isString(prev)) {
|
||||||
if (next[key] == null) {
|
for (const key in prev) {
|
||||||
setStyle(style, key, '')
|
if (next[key] == null) {
|
||||||
|
setStyle(style, key, '')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (const prevStyle of prev.split(';')) {
|
||||||
|
const key = prevStyle.slice(0, prevStyle.indexOf(':')).trim()
|
||||||
|
if (next[key] == null) {
|
||||||
|
setStyle(style, key, '')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue