Skip to content

Commit b997af0

Browse files
posvayyx990803
authored andcommitted
Use genAssignmentCode in chehckbox model web compiler (vuejs#5402)
Fix vuejs#5398
1 parent a150317 commit b997af0

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/platforms/web/compiler/directives/model.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function genCheckboxModel (
9191
'$$i=_i($$a,$$v);' +
9292
`if($$c){$$i<0&&(${value}=$$a.concat($$v))}` +
9393
`else{$$i>-1&&(${value}=$$a.slice(0,$$i).concat($$a.slice($$i+1)))}` +
94-
`}else{${value}=$$c}`,
94+
`}else{${genAssignmentCode(value, '$$c')}}`,
9595
null, true
9696
)
9797
}

test/unit/features/directives/model-checkbox.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,29 @@ describe('Directive v-model checkbox', () => {
256256
expect(vm.$el.checked).toBe(true)
257257
}).then(done)
258258
})
259+
260+
it('triggers a watcher when binding to an array value in a checkbox', done => {
261+
const vm = new Vue({
262+
data: {
263+
test: {
264+
thing: false,
265+
arr: [true]
266+
}
267+
},
268+
template: `
269+
<div>
270+
<input type="checkbox" v-model="test.arr[0]">
271+
<span>{{ test.arr[0] }}</span>
272+
</div>
273+
`
274+
}).$mount()
275+
document.body.appendChild(vm.$el)
276+
expect(vm.$el.children[0].checked).toBe(true)
277+
expect(vm.$el.children[1].textContent).toBe('true')
278+
vm.$el.children[0].click()
279+
expect(vm.$el.children[0].checked).toBe(false)
280+
waitForUpdate(() => {
281+
expect(vm.$el.children[1].textContent).toBe('false')
282+
}).then(done)
283+
})
259284
})

0 commit comments

Comments
 (0)