Skip to content

Commit 931aaea

Browse files
committed
expand .sync into extra listener
1 parent ba13854 commit 931aaea

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/compiler/parser/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { parseText } from './text-parser'
66
import { parseFilters } from './filter-parser'
77
import { cached, no, camelize } from 'shared/util'
88
import { isIE, isServerRendering } from 'core/util/env'
9+
import { genAssignmentCode } from '../directives/model'
910

1011
import {
1112
addProp,
@@ -462,6 +463,13 @@ function processAttrs (el) {
462463
if (modifiers.camel) {
463464
name = camelize(name)
464465
}
466+
if (modifiers.sync) {
467+
addHandler(
468+
el,
469+
`update:${camelize(name)}`,
470+
genAssignmentCode(value, `$event`)
471+
)
472+
}
465473
}
466474
if (isProp || platformMustUseProp(el.tag, el.attrsMap.type, name)) {
467475
addProp(el, name, value)

test/unit/features/directives/bind.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,27 @@ describe('Directive v-bind', () => {
143143
expect(vm.$el.getAttribute('viewBox')).toBe('0 0 1 1')
144144
})
145145

146+
it('.sync modifier', done => {
147+
const vm = new Vue({
148+
template: `<test :foo-bar.sync="bar"/>`,
149+
data: {
150+
bar: 1
151+
},
152+
components: {
153+
test: {
154+
props: ['fooBar'],
155+
template: `<div @click="$emit('update:fooBar', 2)">{{ fooBar }}</div>`
156+
}
157+
}
158+
}).$mount()
159+
160+
expect(vm.$el.textContent).toBe('1')
161+
triggerEvent(vm.$el, 'click')
162+
waitForUpdate(() => {
163+
expect(vm.$el.textContent).toBe('2')
164+
}).then(done)
165+
})
166+
146167
it('bind object', done => {
147168
const vm = new Vue({
148169
template: '<input v-bind="test">',

0 commit comments

Comments
 (0)