File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
src/platforms/web/compiler/directives
test/unit/features/directives Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -93,7 +93,7 @@ function genCheckboxModel (
9393 'if(Array.isArray($$a)){' +
9494 `var $$v=${ number ? '_n(' + valueBinding + ')' : valueBinding } ,` +
9595 '$$i=_i($$a,$$v);' +
96- `if($$el.checked){$$i<0&&(${ value } =$$a.concat($$v))}` +
96+ `if($$el.checked){$$i<0&&(${ value } =$$a.concat([ $$v] ))}` +
9797 `else{$$i>-1&&(${ value } =$$a.slice(0,$$i).concat($$a.slice($$i+1)))}` +
9898 `}else{${ genAssignmentCode ( value , '$$c' ) } }` ,
9999 null , true
Original file line number Diff line number Diff line change @@ -161,6 +161,34 @@ describe('Directive v-model checkbox', () => {
161161 } ) . then ( done )
162162 } )
163163
164+ it ( 'bind to Array value with array value bindings (object loose equal)' , done => {
165+ const vm = new Vue ( {
166+ data : {
167+ test : [ { a : 1 } ]
168+ } ,
169+ template : `
170+ <div>
171+ <input type="checkbox" v-model="test" :value="{ a: 1 }">
172+ <input type="checkbox" v-model="test" :value="[2]">
173+ </div>
174+ `
175+ } ) . $mount ( )
176+ document . body . appendChild ( vm . $el )
177+ expect ( vm . $el . children [ 0 ] . checked ) . toBe ( true )
178+ expect ( vm . $el . children [ 1 ] . checked ) . toBe ( false )
179+ vm . $el . children [ 0 ] . click ( )
180+ expect ( vm . test . length ) . toBe ( 0 )
181+ vm . $el . children [ 1 ] . click ( )
182+ expect ( vm . test ) . toEqual ( [ [ 2 ] ] )
183+ vm . $el . children [ 0 ] . click ( )
184+ expect ( vm . test ) . toEqual ( [ [ 2 ] , { a : 1 } ] )
185+ vm . test = [ { a : 1 } ]
186+ waitForUpdate ( ( ) => {
187+ expect ( vm . $el . children [ 0 ] . checked ) . toBe ( true )
188+ expect ( vm . $el . children [ 1 ] . checked ) . toBe ( false )
189+ } ) . then ( done )
190+ } )
191+
164192 it ( '.number modifier' , ( ) => {
165193 const vm = new Vue ( {
166194 data : {
You can’t perform that action at this time.
0 commit comments