Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/compiler/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { parseHTML } from './html-parser'
import { parseText } from './text-parser'
import { parseFilters } from './filter-parser'
import { genAssignmentCode } from '../directives/model'
import { extend, cached, no, camelize } from 'shared/util'
import { extend, cached, no, camelize, hyphenate } from 'shared/util'
import { isIE, isEdge, isServerRendering } from 'core/util/env'

import {
Expand Down Expand Up @@ -512,7 +512,7 @@ function processComponent (el) {

function processAttrs (el) {
const list = el.attrsList
let i, l, name, rawName, value, modifiers, isProp
let i, l, name, rawName, value, modifiers, isProp, syncGen
for (i = 0, l = list.length; i < l; i++) {
name = rawName = list[i].name
value = list[i].value
Expand All @@ -538,11 +538,19 @@ function processAttrs (el) {
name = camelize(name)
}
if (modifiers.sync) {
syncGen = genAssignmentCode(value, `$event`)
addHandler(
el,
`update:${camelize(name)}`,
genAssignmentCode(value, `$event`)
syncGen
)
if (hyphenate(name) !== camelize(name)) {
addHandler(
el,
`update:${hyphenate(name)}`,
syncGen
)
}
}
}
if (isProp || (
Expand Down
21 changes: 21 additions & 0 deletions test/unit/features/directives/bind.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,27 @@ describe('Directive v-bind', () => {
}).then(done)
})

it('.sync modifier with kebab case event', done => {
const vm = new Vue({
template: `<test :foo-bar.sync="bar"/>`,
data: {
bar: 1
},
components: {
test: {
props: ['fooBar'],
template: `<div @click="$emit('update:foo-bar', 2)">{{ fooBar }}</div>`
}
}
}).$mount()

expect(vm.$el.textContent).toBe('1')
triggerEvent(vm.$el, 'click')
waitForUpdate(() => {
expect(vm.$el.textContent).toBe('2')
}).then(done)
})

it('bind object', done => {
const vm = new Vue({
template: '<input v-bind="test">',
Expand Down