Browse Source

`v-style` set cssText when no arg is present

Evan You 12 years ago
parent
commit
97c1a811d3
2 changed files with 21 additions and 8 deletions
  1. 13 8
      src/directives/style.js
  2. 8 0
      test/unit/specs/directives.js

+ 13 - 8
src/directives/style.js

@@ -8,8 +8,9 @@ function camelReplacer (m) {
 module.exports = {
 
     bind: function () {
-        var prop = this.arg,
-            first = prop.charAt(0)
+        var prop = this.arg
+        if (!prop) return
+        var first = prop.charAt(0)
         if (first === '$') {
             // properties that start with $ will be auto-prefixed
             prop = prop.slice(1)
@@ -23,13 +24,17 @@ module.exports = {
 
     update: function (value) {
         var prop = this.prop
-        this.el.style[prop] = value
-        if (this.prefixed) {
-            prop = prop.charAt(0).toUpperCase() + prop.slice(1)
-            var i = prefixes.length
-            while (i--) {
-                this.el.style[prefixes[i] + prop] = value
+        if (prop) {
+            this.el.style[prop] = value
+            if (this.prefixed) {
+                prop = prop.charAt(0).toUpperCase() + prop.slice(1)
+                var i = prefixes.length
+                while (i--) {
+                    this.el.style[prefixes[i] + prop] = value
+                }
             }
+        } else {
+            this.el.style.cssText = value
         }
     }
 

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

@@ -730,6 +730,14 @@ describe('UNIT: Directives', function () {
             assert.strictEqual(d.el.style.msTransform, val)
         })
 
+        it('should set cssText if no arg', function () {
+            var d = mockDirective('style')
+            d.bind()
+            var val = 'color:#fff'
+            d.update(val)
+            assert.strictEqual(d.el.style.color, 'rgb(255, 255, 255)')
+        })
+
     })
 
     describe('cloak', function () {