From cfcdf3f9bf5ff69aa9c3b8908a5880478731a4eb Mon Sep 17 00:00:00 2001 From: loveverse <398096830@qq.com> Date: Mon, 15 Jun 2026 11:00:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Select=E4=BA=8C=E7=BA=A7=E8=81=94?= =?UTF-8?q?=E5=8A=A8=E6=B8=85=E7=A9=BA=E5=90=8E=E9=87=8D=E6=96=B0=E9=80=89?= =?UTF-8?q?=E6=8B=A9label=E6=9C=AA=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在Select组件二级联动场景中,清空选择后再次选择时,二级选项的label仍显示上一次的值。 原因:optionLabel和filter方法中直接读取this.$el.textContent,DOM更新存在时序问题导致获取到旧值。 修复:新增searchLabel数据属性,在mounted/updated生命周期中同步更新,替代直接读取DOM文本。 --- src/components/select/option.vue | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/components/select/option.vue b/src/components/select/option.vue index e9d09046..46e351ab 100644 --- a/src/components/select/option.vue +++ b/src/components/select/option.vue @@ -67,7 +67,7 @@ return (this.label) ? this.label : this.value; }, optionLabel(){ - return this.label || (this.$el && this.$el.textContent); + return this.label || this.searchLabel; }, isFocused(){ const SelectInstance = this.SelectInstance; @@ -103,7 +103,7 @@ const filterByLabel = SelectInstance.filterByLabel; const slotOptionsMap = SelectInstance.slotOptionsMap; const { props } = slotOptionsMap.get(this.value) || { props: {} }; - const label = this.label || this.$el && this.$el.textContent; + const label = this.label || this.searchLabel; let filterOption = String(label ?? props.value ?? '').toLowerCase(); if (filterByLabel) { filterOption = String(label != null ? label : '').toLowerCase(); @@ -168,13 +168,26 @@ created(){ this.instance = getCurrentInstance(); }, + updated () { + this.searchLabel = (this.$el && this.$el.textContent) || ''; + }, mounted () { + this.searchLabel = (this.$el && this.$el.textContent) || ''; this.addOption(); const Select = findComponentUpward(this, 'iSelect'); if (Select) { this.autoComplete = Select.autoComplete; } }, + watch: { + value (newVal, oldVal) { + const select = this.SelectInstance; + if (select && newVal !== oldVal) { + select.slotOptionsMap.has(oldVal) && select.slotOptionsMap.delete(oldVal); + select.slotOptionsMap.set(newVal, this.instance); + } + } + }, beforeUnmount () { // fix AutoComplete. when suggest the word, the dropdown will hide nextTick(() => {