Browse Source

fix camelCase directive params (fix #2565)

Evan You 10 years ago
parent
commit
4a71e01f53
2 changed files with 7 additions and 2 deletions
  1. 2 1
      src/directive.js
  2. 5 1
      test/unit/specs/directive_spec.js

+ 2 - 1
src/directive.js

@@ -6,6 +6,7 @@ import {
   getAttr,
   getBindAttr,
   camelize,
+  hyphenate,
   nextTick,
   warn
 } from './util/index'
@@ -166,7 +167,7 @@ Directive.prototype._setupParams = function () {
   var i = params.length
   var key, val, mappedKey
   while (i--) {
-    key = params[i]
+    key = hyphenate(params[i])
     mappedKey = camelize(key)
     val = getBindAttr(this.el, key)
     if (val != null) {

+ 5 - 1
test/unit/specs/directive_spec.js

@@ -7,7 +7,7 @@ describe('Directive', function () {
   beforeEach(function () {
     el = document.createElement('div')
     def = {
-      params: ['foo'],
+      params: ['foo', 'keBab'],
       paramWatchers: {
         foo: jasmine.createSpy('foo')
       },
@@ -159,6 +159,7 @@ describe('Directive', function () {
 
   it('static params', function () {
     el.setAttribute('foo', 'hello')
+    el.setAttribute('ke-bab', 'yo')
     var d = new Directive({
       name: 'test',
       def: def,
@@ -166,10 +167,12 @@ describe('Directive', function () {
     }, vm, el)
     d._bind()
     expect(d.params.foo).toBe('hello')
+    expect(d.params.keBab).toBe('yo')
   })
 
   it('dynamic params', function (done) {
     el.setAttribute(':foo', 'a')
+    el.setAttribute(':ke-bab', '123')
     var d = new Directive({
       name: 'test',
       def: def,
@@ -177,6 +180,7 @@ describe('Directive', function () {
     }, vm, el)
     d._bind()
     expect(d.params.foo).toBe(vm.a)
+    expect(d.params.keBab).toBe(123)
     vm.a = 2
     nextTick(function () {
       expect(def.paramWatchers.foo).toHaveBeenCalledWith(2, 1)