Skip to content

Commit

Permalink
Use genAssignmentCode in chehckbox model web compiler (#5402)
Browse files Browse the repository at this point in the history
Fix #5398
  • Loading branch information
posva authored and yyx990803 committed Apr 10, 2017
1 parent a150317 commit b997af0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/platforms/web/compiler/directives/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function genCheckboxModel (
'$$i=_i($$a,$$v);' +
`if($$c){$$i<0&&(${value}=$$a.concat($$v))}` +
`else{$$i>-1&&(${value}=$$a.slice(0,$$i).concat($$a.slice($$i+1)))}` +
`}else{${value}=$$c}`,
`}else{${genAssignmentCode(value, '$$c')}}`,
null, true
)
}
Expand Down
25 changes: 25 additions & 0 deletions test/unit/features/directives/model-checkbox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,29 @@ describe('Directive v-model checkbox', () => {
expect(vm.$el.checked).toBe(true)
}).then(done)
})

it('triggers a watcher when binding to an array value in a checkbox', done => {
const vm = new Vue({
data: {
test: {
thing: false,
arr: [true]
}
},
template: `
<div>
<input type="checkbox" v-model="test.arr[0]">
<span>{{ test.arr[0] }}</span>
</div>
`
}).$mount()
document.body.appendChild(vm.$el)
expect(vm.$el.children[0].checked).toBe(true)
expect(vm.$el.children[1].textContent).toBe('true')
vm.$el.children[0].click()
expect(vm.$el.children[0].checked).toBe(false)
waitForUpdate(() => {
expect(vm.$el.children[1].textContent).toBe('false')
}).then(done)
})
})

0 comments on commit b997af0

Please sign in to comment.