diff --git a/packages/runtime-dom/src/directives/vShow.ts b/packages/runtime-dom/src/directives/vShow.ts index ee2aff0b856..1d31d5ca961 100644 --- a/packages/runtime-dom/src/directives/vShow.ts +++ b/packages/runtime-dom/src/directives/vShow.ts @@ -1,8 +1,10 @@ import { ObjectDirective } from '@vue/runtime-core' -interface VShowElement extends HTMLElement { +export interface VShowElement extends HTMLElement { // _vod = vue original display _vod: string + // _vds = vue display status + _vds: boolean } export const vShow: ObjectDirective = { @@ -41,7 +43,7 @@ export const vShow: ObjectDirective = { } function setDisplay(el: VShowElement, value: unknown): void { - el.style.display = value ? el._vod : 'none' + el.style.display = (el._vds = !!value) ? el._vod : 'none' } // SSR vnode transforms, only used when user includes client-oriented render diff --git a/packages/runtime-dom/src/modules/style.ts b/packages/runtime-dom/src/modules/style.ts index 69a608795d9..ccfdfff95d5 100644 --- a/packages/runtime-dom/src/modules/style.ts +++ b/packages/runtime-dom/src/modules/style.ts @@ -1,5 +1,6 @@ import { isString, hyphenate, capitalize, isArray } from '@vue/shared' import { camelize } from '@vue/runtime-core' +import { VShowElement } from '../directives/vShow' type Style = string | Record | null @@ -27,8 +28,12 @@ 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 + if ('_vod' in el && currentDisplay !== style.display) { + (el as VShowElement)._vod = style.display; + if (!(el as VShowElement)._vds) { + // if vshow was set to hide + style.display = currentDisplay; + } } }