Просмотр исходного кода

fix style binding for falsy numbers (fix #3816)

Evan You 9 лет назад
Родитель
Сommit
6d4bdb5ff1

+ 1 - 1
src/platforms/web/runtime/modules/style.js

@@ -57,7 +57,7 @@ function updateStyle (oldVnode: VNodeWithData, vnode: VNodeWithData) {
     cur = style[name]
     if (cur !== oldStyle[name]) {
       // ie9 setting to null has no effect, must use empty string
-      el.style[normalize(name)] = cur || ''
+      el.style[normalize(name)] = cur == null ? '' : cur
     }
   }
 }

+ 7 - 0
test/unit/features/directives/style.spec.js

@@ -37,6 +37,13 @@ describe('Directive v-bind:style', () => {
     }).then(done)
   })
 
+  it('falsy number', done => {
+    vm.styles = { opacity: 0 }
+    waitForUpdate(() => {
+      expect(vm.$el.style.opacity).toBe('0')
+    }).then(done)
+  })
+
   it('plain object', done => {
     vm.styles = { color: 'red' }
     waitForUpdate(() => {