fix(v-model): mutate original array for v-model multi checkbox (#2663)

Note: this change will break non-deep `watch` on the `v-model` bound array since the array is no longer replaced. This can be considered part of the Array watch changes in v3 as detailed at https://v3.vuejs.org/guide/migration/watch.html

This is unfortunate but unavoidable since the issue that it fixes is more important: `v-model` should definitely work with a non-ref reactive array.

fix #2662
This commit is contained in:
HcySunYang
2020-12-01 06:48:51 +08:00
committed by GitHub
parent cd92836223
commit 87581cd266
2 changed files with 76 additions and 5 deletions

View File

@@ -111,11 +111,9 @@ export const vModelCheckbox: ModelDirective<HTMLInputElement> = {
const index = looseIndexOf(modelValue, elementValue)
const found = index !== -1
if (checked && !found) {
assign(modelValue.concat(elementValue))
modelValue.push(elementValue)
} else if (!checked && found) {
const filtered = [...modelValue]
filtered.splice(index, 1)
assign(filtered)
modelValue.splice(index, 1)
}
} else if (isSet(modelValue)) {
if (checked) {