Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/platforms/web/runtime/modules/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function updateStyle(oldVnode: VNodeWithData, vnode: VNodeWithData) {
// to mutate it.
vnode.data.normalizedStyle = isDef(style.__ob__) ? extend({}, style) : style

const newStyle = getStyle(vnode, true)
const newStyle = getStyle(vnode, true) as any

for (name in oldStyle) {
if (isUndef(newStyle[name])) {
Expand All @@ -94,6 +94,14 @@ function updateStyle(oldVnode: VNodeWithData, vnode: VNodeWithData) {
// ie9 setting to null has no effect, must use empty string
setProp(el, name, cur == null ? '' : cur)
}
// determines if `v-show` is set, it has a higher priority.
if ('__vOriginalDisplay' in el) {
setProp(el, 'display', el.__vOriginalDisplay)
const vShowDirective = data.directives?.find(d => d.name === 'show')
if (vShowDirective && !vShowDirective.value) {
setProp(el, 'display', 'none')
}
}
}

export default {
Expand Down
17 changes: 17 additions & 0 deletions test/unit/features/directives/show.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,21 @@ describe('Directive v-show', () => {
})
.then(done)
})

it('should prefer to use v-show to update display', done => {
const vm = new Vue({
template: '<div v-show="display" :style="style">{{ count }}</div>',
data: { display: false, count: 1, style: { display: 'block' } }
}).$mount()
expect(vm.$el.style.display).toBe('none')
vm.count++
waitForUpdate(() => {
expect(vm.$el.style.display).toBe('none')
vm.display = true
})
.then(() => {
expect(vm.$el.style.display).toBe('block')
})
.then(done)
})
})