Skip to content

Commit 09f7f9c

Browse files
fix: 🐛 修复 Collapse v-model绑定数据变化时未更新折叠面板状态的问题 (#744)
Closes: #741
1 parent fb7580d commit 09f7f9c

2 files changed

Lines changed: 11 additions & 17 deletions

File tree

src/uni_modules/wot-design-uni/components/wd-collapse-item/wd-collapse-item.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default {
3131

3232
<script lang="ts" setup>
3333
import wdIcon from '../wd-icon/wd-icon.vue'
34-
import { computed, getCurrentInstance, onMounted, ref, type CSSProperties } from 'vue'
34+
import { computed, getCurrentInstance, onMounted, ref, watch, type CSSProperties } from 'vue'
3535
import { addUnit, getRect, isArray, isDef, isPromise, isString, objToStyle, requestAnimationFrame, uuid } from '../common/util'
3636
import { useParent } from '../composables/useParent'
3737
import { COLLAPSE_KEY } from '../wd-collapse/types'
@@ -80,6 +80,13 @@ const isSelected = computed(() => {
8080
return (isString(modelValue) && modelValue === name) || (isArray(modelValue) && modelValue.indexOf(name as string) >= 0)
8181
})
8282
83+
watch(
84+
() => isSelected.value,
85+
(newVal) => {
86+
updateExpand(newVal)
87+
}
88+
)
89+
8390
onMounted(() => {
8491
updateExpand(isSelected.value)
8592
})

src/uni_modules/wot-design-uni/components/wd-collapse/wd-collapse.vue

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ watch(
6969
console.error('value must be Array')
7070
}
7171
},
72-
{ deep: true, immediate: true }
72+
{ deep: true }
7373
)
7474
7575
watch(
@@ -94,22 +94,10 @@ function updateChange(activeNames: string | string[] | boolean) {
9494
})
9595
}
9696
97-
// 更新全部自组件展开状态
98-
const updateChildren = async () => {
99-
for (const item of children) {
100-
try {
101-
await item.$.exposed!.updateExpand()
102-
} catch (error) {
103-
console.warn(`更新折叠面板状态失败: ${error}`)
104-
}
105-
}
106-
}
107-
108-
async function toggle(name: string, expanded: boolean) {
97+
function toggle(name: string, expanded: boolean) {
10998
const { accordion, modelValue } = props
11099
if (accordion) {
111100
updateChange(name === modelValue ? '' : name)
112-
await updateChildren()
113101
} else if (expanded) {
114102
updateChange((modelValue as string[]).concat(name))
115103
} else {
@@ -121,7 +109,7 @@ async function toggle(name: string, expanded: boolean) {
121109
* 切换所有面板展开状态,传 true 为全部展开,false 为全部收起,不传参为全部切换
122110
* @param options 面板状态
123111
*/
124-
const toggleAll = async (options: CollapseToggleAllOptions = {}) => {
112+
const toggleAll = (options: CollapseToggleAllOptions = {}) => {
125113
if (props.accordion) {
126114
return
127115
}
@@ -141,7 +129,6 @@ const toggleAll = async (options: CollapseToggleAllOptions = {}) => {
141129
}
142130
})
143131
updateChange(names)
144-
await updateChildren()
145132
}
146133
147134
/**

0 commit comments

Comments
 (0)