Skip to content

Commit

Permalink
fix: v-bind object should be overridable with kebab-cased props (#8845)
Browse files Browse the repository at this point in the history
In addition .sync should generate camelCased event name
  • Loading branch information
Justineo authored and yyx990803 committed Nov 30, 2018
1 parent 80f17fa commit 7585241
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/core/instance/render-helpers/bind-object-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
warn,
isObject,
toObject,
isReservedAttribute
isReservedAttribute,
camelize
} from 'core/util/index'

/**
Expand Down Expand Up @@ -43,12 +44,13 @@ export function bindObjectProps (
? data.domProps || (data.domProps = {})
: data.attrs || (data.attrs = {})
}
if (!(key in hash)) {
const camelizedKey = camelize(key)
if (!(key in hash) && !(camelizedKey in hash)) {
hash[key] = value[key]

if (isSync) {
const on = data.on || (data.on = {})
on[`update:${key}`] = function ($event) {
on[`update:${camelizedKey}`] = function ($event) {
value[key] = $event
}
}
Expand Down
20 changes: 20 additions & 0 deletions test/unit/features/directives/bind.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,26 @@ describe('Directive v-bind', () => {
}).then(done)
})

it('bind object with explicit overrides', () => {
const vm = new Vue({
template: `<test v-bind="test" data-foo="foo" dataBar="bar"/>`,
components: {
test: {
template: '<div :data-foo="dataFoo" :data-bar="dataBar"></div>',
props: ['dataFoo', 'dataBar']
}
},
data: {
test: {
dataFoo: 'hi',
dataBar: 'bye'
}
}
}).$mount()
expect(vm.$el.getAttribute('data-foo')).toBe('foo')
expect(vm.$el.getAttribute('data-bar')).toBe('bar')
})

it('.sync modifier with bind object', done => {
const vm = new Vue({
template: `<test v-bind.sync="test"/>`,
Expand Down

0 comments on commit 7585241

Please sign in to comment.