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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user