Skip to content

Commit

Permalink
fix(Checkbox): v-model cannot be listened by watch
Browse files Browse the repository at this point in the history
  • Loading branch information
qiqingfu committed Dec 14, 2020
1 parent 49e1d98 commit 1888754
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/element3/packages/checkbox/uses.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,17 @@ export function useModel() {
set({ label, checked }) {
if (label && isArray(model.value)) {
// when modelValue or elCheckboxGroup.modeValue is array
const modelValue = model.value
let modelValue = model.value
const labelIndex = modelValue.indexOf(label)
labelIndex === -1 && checked === true && modelValue.push(label)
labelIndex !== -1 &&
checked === false &&
modelValue.splice(labelIndex, 1)

if (labelIndex === -1 && checked === true) {
modelValue = modelValue.concat(label)
}

if (labelIndex !== -1 && checked === false) {
modelValue = modelValue.splice(labelIndex, 1)
}

state.modelValue = modelValue
emit('update:modelValue', modelValue)
dispatch('update:modelValue', modelValue)
Expand Down

0 comments on commit 1888754

Please sign in to comment.