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

fix #310 v-style fails with number values

Evan You 12 лет назад
Родитель
Сommit
a49e5616dd
2 измененных файлов с 12 добавлено и 1 удалено
  1. 4 1
      src/directives/style.js
  2. 8 0
      test/unit/specs/directives.js

+ 4 - 1
src/directives/style.js

@@ -19,8 +19,11 @@ module.exports = {
     update: function (value) {
         var prop = this.prop,
             isImportant
+        /* jshint eqeqeq: true */
+        // cast possible numbers/booleans into strings
+        if (value != null) value += ''
         if (prop) {
-            if (value){
+            if (value) {
                 isImportant = value.slice(-10) === '!important'
                     ? 'important'
                     : ''

+ 8 - 0
test/unit/specs/directives.js

@@ -715,6 +715,14 @@ describe('Directives', function () {
             assert.strictEqual(d.el.style.color, 'rgb(255, 255, 255)')
         })
 
+        it('should work with numbers', function () {
+            var d = mockDirective('style')
+            d.arg = 'line-height'
+            d.bind()
+            d.update(0)
+            assert.strictEqual(d.el.style.lineHeight, '0')
+        })
+
     })
 
     describe('cloak', function () {