From a7724fec7b7f5bbe3bf105650b6d6a22f813d35b Mon Sep 17 00:00:00 2001 From: chouchouji <1305974212@qq.com> Date: Tue, 2 Sep 2025 15:03:00 +0800 Subject: [PATCH] =?UTF-8?q?fix(uni-collapse):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=9D=9E=E6=89=8B=E9=A3=8E=E7=90=B4=E6=A8=A1=E5=BC=8F=E4=B8=8B?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E8=AE=BE=E7=BD=AEmodeValue=E4=B8=BA[]?= =?UTF-8?q?=E7=9A=84Bug=20(question/205130)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/uni-collapse/uni-collapse.vue | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/uni_modules/uni-collapse/components/uni-collapse/uni-collapse.vue b/uni_modules/uni-collapse/components/uni-collapse/uni-collapse.vue index f87bb253d..ba91b9b5c 100644 --- a/uni_modules/uni-collapse/components/uni-collapse/uni-collapse.vue +++ b/uni_modules/uni-collapse/components/uni-collapse/uni-collapse.vue @@ -51,7 +51,7 @@ } }, watch: { - dataValue(val) { + dataValue(val) { this.setOpen(val) } }, @@ -59,16 +59,16 @@ this.childrens = [] this.names = [] }, - mounted() { - this.$nextTick(()=>{ - this.setOpen(this.dataValue) - }) + mounted() { + this.$nextTick(()=>{ + this.setOpen(this.dataValue) + }) }, methods: { setOpen(val) { - let str = typeof val === 'string' - let arr = Array.isArray(val) - this.childrens.forEach((vm, index) => { + const str = typeof val === 'string' + const arr = Array.isArray(val) + this.childrens.forEach((vm) => { if (str) { if (val === vm.nameSync) { if (!this.accordion) { @@ -77,17 +77,14 @@ } vm.isOpen = true } - } + } if (arr) { - val.forEach(v => { - if (v === vm.nameSync) { - if (this.accordion) { - console.warn('accordion 属性为 true ,v-model 类型应该为 string') - return - } - vm.isOpen = true - } - }) + const isOpen = val.findIndex(v => v === vm.nameSync) !== -1 + if (this.accordion && isOpen) { + console.warn('accordion 属性为 true ,v-model 类型应该为 string') + return + } + vm.isOpen = isOpen } }) this.emit(val)