File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
test/unit/features/directives Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { parseText } from './text-parser'
6
6
import { parseFilters } from './filter-parser'
7
7
import { cached , no , camelize } from 'shared/util'
8
8
import { isIE , isServerRendering } from 'core/util/env'
9
+ import { genAssignmentCode } from '../directives/model'
9
10
10
11
import {
11
12
addProp ,
@@ -462,6 +463,13 @@ function processAttrs (el) {
462
463
if ( modifiers . camel ) {
463
464
name = camelize ( name )
464
465
}
466
+ if ( modifiers . sync ) {
467
+ addHandler (
468
+ el ,
469
+ `update:${ camelize ( name ) } ` ,
470
+ genAssignmentCode ( value , `$event` )
471
+ )
472
+ }
465
473
}
466
474
if ( isProp || platformMustUseProp ( el . tag , el . attrsMap . type , name ) ) {
467
475
addProp ( el , name , value )
Original file line number Diff line number Diff line change @@ -143,6 +143,27 @@ describe('Directive v-bind', () => {
143
143
expect ( vm . $el . getAttribute ( 'viewBox' ) ) . toBe ( '0 0 1 1' )
144
144
} )
145
145
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
+
146
167
it ( 'bind object' , done => {
147
168
const vm = new Vue ( {
148
169
template : '<input v-bind="test">' ,
You can’t perform that action at this time.
0 commit comments