diff --git a/src/uni_modules/wot-design-uni/components/wd-collapse-item/types.ts b/src/uni_modules/wot-design-uni/components/wd-collapse-item/types.ts index c796c7c5..e2056b9c 100644 --- a/src/uni_modules/wot-design-uni/components/wd-collapse-item/types.ts +++ b/src/uni_modules/wot-design-uni/components/wd-collapse-item/types.ts @@ -31,6 +31,11 @@ export type CollapseItemExpose = { * @returns boolean */ getExpanded: () => boolean + /** + * 更新展开状态 + * @returns Promise + */ + updateExpand: () => Promise } export type CollapseItemInstance = ComponentPublicInstance diff --git a/src/uni_modules/wot-design-uni/components/wd-collapse-item/wd-collapse-item.vue b/src/uni_modules/wot-design-uni/components/wd-collapse-item/wd-collapse-item.vue index e0d63144..47d8bb8a 100644 --- a/src/uni_modules/wot-design-uni/components/wd-collapse-item/wd-collapse-item.vue +++ b/src/uni_modules/wot-design-uni/components/wd-collapse-item/wd-collapse-item.vue @@ -74,25 +74,11 @@ const selected = computed(() => { } }) -watch( - () => selected.value, - () => { - if (!inited.value) { - return - } - updateExpend() - }, - { - deep: true, - immediate: true - } -) - onMounted(() => { - updateExpend() + updateExpand() }) -function updateExpend() { +function updateExpand() { return getRect(`#${collapseId.value}`, false, proxy).then((rect) => { const { height: rectHeight } = rect height.value = isDef(rectHeight) ? Number(rectHeight) : '' @@ -136,16 +122,16 @@ function handleClick() { } if (isPromise(response)) { response.then(() => { - collapse && collapse.toggle(name, !expanded.value) + handleChangeExpand(name) }) } else { - collapse && collapse.toggle(name, !expanded.value) + handleChangeExpand(name) } } else { - collapse && collapse.toggle(name, !expanded.value) + handleChangeExpand(name) } } else { - collapse && collapse.toggle(name, !expanded.value) + handleChangeExpand(name) } } @@ -153,7 +139,12 @@ function getExpanded() { return expanded.value } -defineExpose({ getExpanded }) +function handleChangeExpand(name: string) { + updateExpand() + collapse && collapse.toggle(name, !expanded.value) +} + +defineExpose({ getExpanded, updateExpand })