Ver código fonte

add .camel modifier for v-bind (workaround for #2250)

Evan You 10 anos atrás
pai
commit
ad7585f5d1

+ 4 - 1
src/directives/public/bind.js

@@ -1,4 +1,4 @@
-import { warn, setClass } from '../../util/index'
+import { warn, setClass, camelize } from '../../util/index'
 import { BIND } from '../priorities'
 import vStyle from '../internal/style'
 import { tokensToExp } from '../../parsers/text'
@@ -96,6 +96,9 @@ export default {
   handleSingle (attr, value) {
     const el = this.el
     const interp = this.descriptor.interp
+    if (this.modifiers.camel) {
+      attr = camelize(attr)
+    }
     if (
       !interp &&
       attrWithPropsRE.test(attr) &&

+ 12 - 1
test/unit/specs/directives/public/bind_spec.js

@@ -9,7 +9,8 @@ describe('v-bind', function () {
     el = document.createElement('div')
     dir = {
       el: el,
-      descriptor: {}
+      descriptor: {},
+      modifiers: {}
     }
     _.extend(dir, def)
   })
@@ -70,4 +71,14 @@ describe('v-bind', function () {
     dir.update(null)
     expect(dir.el.hasAttributeNS(xlinkNS, 'special')).toBe(false)
   })
+
+  it('camel modifier', function () {
+    dir.modifiers.camel = true
+    var div = document.createElement('div')
+    div.innerHTML = '<svg></svg>'
+    dir.el = div.children[0]
+    dir.arg = 'view-box'
+    dir.update('0 0 1500 1000')
+    expect(dir.el.getAttribute('viewBox')).toBe('0 0 1500 1000')
+  })
 })