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)

AltStyle によって変換されたページ (->オリジナル) /