diff --git a/packages/runtime-dom/src/modules/style.ts b/packages/runtime-dom/src/modules/style.ts index 69a608795d9..e4cdd893b81 100644 --- a/packages/runtime-dom/src/modules/style.ts +++ b/packages/runtime-dom/src/modules/style.ts @@ -6,11 +6,22 @@ type Style = string | Record | null export function patchStyle(el: Element, prev: Style, next: Style) { const style = (el as HTMLElement).style const currentDisplay = style.display + // indicates that the `display` of the element is controlled by `v-show`, + // so we always keep the current `display` value regardless of the `style` value, + // thus handing over control to `v-show`. + const resetDisplay = () => { + if ('_vod' in el) { + style.display = currentDisplay + } + } + if (!next) { el.removeAttribute('style') + resetDisplay() } else if (isString(next)) { if (prev !== next) { style.cssText = next + resetDisplay() } } else { for (const key in next) { @@ -24,12 +35,6 @@ export function patchStyle(el: Element, prev: Style, next: Style) { } } } - // indicates that the `display` of the element is controlled by `v-show`, - // so we always keep the current `display` value regardless of the `style` value, - // thus handing over control to `v-show`. - if ('_vod' in el) { - style.display = currentDisplay - } } const importantRE = /\s*!important$/