Skip to content

Commit 4a71e01

Browse files
committed
fix camelCase directive params (fix #2565)
1 parent 35883fa commit 4a71e01

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/directive.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
getAttr,
77
getBindAttr,
88
camelize,
9+
hyphenate,
910
nextTick,
1011
warn
1112
} from './util/index'
@@ -166,7 +167,7 @@ Directive.prototype._setupParams = function () {
166167
var i = params.length
167168
var key, val, mappedKey
168169
while (i--) {
169-
key = params[i]
170+
key = hyphenate(params[i])
170171
mappedKey = camelize(key)
171172
val = getBindAttr(this.el, key)
172173
if (val != null) {

test/unit/specs/directive_spec.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe('Directive', function () {
77
beforeEach(function () {
88
el = document.createElement('div')
99
def = {
10-
params: ['foo'],
10+
params: ['foo', 'keBab'],
1111
paramWatchers: {
1212
foo: jasmine.createSpy('foo')
1313
},
@@ -159,24 +159,28 @@ describe('Directive', function () {
159159

160160
it('static params', function () {
161161
el.setAttribute('foo', 'hello')
162+
el.setAttribute('ke-bab', 'yo')
162163
var d = new Directive({
163164
name: 'test',
164165
def: def,
165166
expression: 'a'
166167
}, vm, el)
167168
d._bind()
168169
expect(d.params.foo).toBe('hello')
170+
expect(d.params.keBab).toBe('yo')
169171
})
170172

171173
it('dynamic params', function (done) {
172174
el.setAttribute(':foo', 'a')
175+
el.setAttribute(':ke-bab', '123')
173176
var d = new Directive({
174177
name: 'test',
175178
def: def,
176179
expression: 'a'
177180
}, vm, el)
178181
d._bind()
179182
expect(d.params.foo).toBe(vm.a)
183+
expect(d.params.keBab).toBe(123)
180184
vm.a = 2
181185
nextTick(function () {
182186
expect(def.paramWatchers.foo).toHaveBeenCalledWith(2, 1)

0 commit comments

Comments
 (0)