Cascader: fix delete tag bug (#20939)

pull/20940/head
好多大米 2021-04-16 16:16:23 +08:00 committed by GitHub
parent 655d89fe0e
commit 486219a752
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 6 deletions

View File

@ -44,14 +44,14 @@
<div v-if="multiple" class="el-cascader__tags"> <div v-if="multiple" class="el-cascader__tags">
<el-tag <el-tag
v-for="(tag, index) in presentTags" v-for="tag in presentTags"
:key="tag.key" :key="tag.key"
type="info" type="info"
:size="tagSize" :size="tagSize"
:hit="tag.hitState" :hit="tag.hitState"
:closable="tag.closable" :closable="tag.closable"
disable-transitions disable-transitions
@close="deleteTag(index)"> @close="deleteTag(tag)">
<span>{{ tag.text }}</span> <span>{{ tag.text }}</span>
</el-tag> </el-tag>
<input <input
@ -588,7 +588,7 @@ export default {
if (this.pressDeleteCount) { if (this.pressDeleteCount) {
if (lastTag.hitState) { if (lastTag.hitState) {
this.deleteTag(lastIndex); this.deleteTag(lastTag);
} else { } else {
lastTag.hitState = true; lastTag.hitState = true;
} }
@ -607,10 +607,11 @@ export default {
this.toggleDropDownVisible(false); this.toggleDropDownVisible(false);
} }
}, },
deleteTag(index) { deleteTag(tag) {
const { checkedValue } = this; const { checkedValue } = this;
const val = checkedValue[index]; const current = tag.node.getValueByOption();
this.checkedValue = checkedValue.filter((n, i) => i !== index); const val = checkedValue.find(n => isEqual(n, current));
this.checkedValue = checkedValue.filter(n => !isEqual(n, current));
this.$emit('remove-tag', val); this.$emit('remove-tag', val);
}, },
updateStyle() { updateStyle() {