Skip to content

Commit

Permalink
fix(components): [cascader] modelValue update problem (#10119)
Browse files Browse the repository at this point in the history
* fix(components): [cascader] modelValue update problem

* fix(components): [cascader-panel] modelValue update

* fix(components): [cascader] use cloneDeep
  • Loading branch information
xiaochenchen-igg-com committed Oct 19, 2022
1 parent 36b6106 commit aafdafa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
20 changes: 13 additions & 7 deletions packages/components/cascader-panel/src/index.vue
Expand Up @@ -26,7 +26,7 @@ import {
ref,
watch,
} from 'vue'
import { flattenDeep, isEqual } from 'lodash-unified'
import { cloneDeep, flattenDeep, isEqual } from 'lodash-unified'
import { isClient } from '@vueuse/core'
import {
castArray,
Expand Down Expand Up @@ -238,7 +238,7 @@ export default defineComponent({
values.map((val) => store?.getNodeByValue(val, leafOnly))
) as Node[]
syncMenuState(nodes, forced)
checkedValue.value = modelValue!
checkedValue.value = cloneDeep(modelValue)
}
}
Expand Down Expand Up @@ -348,15 +348,21 @@ export default defineComponent({
() => {
manualChecked = false
syncCheckedValue()
},
{
deep: true,
}
)
watch(checkedValue, (val) => {
if (!isEqual(val, props.modelValue)) {
emit(UPDATE_MODEL_EVENT, val)
emit(CHANGE_EVENT, val)
watch(
() => checkedValue.value,
(val) => {
if (!isEqual(val, props.modelValue)) {
emit(UPDATE_MODEL_EVENT, val)
emit(CHANGE_EVENT, val)
}
}
})
)
onBeforeUpdate(() => (menuList.value = []))
Expand Down
4 changes: 2 additions & 2 deletions packages/components/cascader/src/index.vue
Expand Up @@ -196,7 +196,7 @@
// @ts-nocheck
import { computed, defineComponent, nextTick, onMounted, ref, watch } from 'vue'
import { isPromise } from '@vue/shared'
import { debounce } from 'lodash-unified'
import { cloneDeep, debounce } from 'lodash-unified'
import { isClient, useResizeObserver } from '@vueuse/core'
import ElCascaderPanel, {
Expand Down Expand Up @@ -416,7 +416,7 @@ export default defineComponent({
const checkedValue = computed<CascaderValue>({
get() {
return props.modelValue as CascaderValue
return cloneDeep(props.modelValue) as CascaderValue
},
set(val) {
emit(UPDATE_MODEL_EVENT, val)
Expand Down

0 comments on commit aafdafa

Please sign in to comment.