fix: select option does not delete in onBeforeMount (#2753)

Co-authored-by: zhaozhongyu <zhaozhongyu@xunlei.com>
This commit is contained in:
zhaozhongyu 2021-08-03 09:37:52 +08:00 committed by GitHub
parent c96b43e14b
commit bcf48a2c8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -67,20 +67,21 @@ export default defineComponent({
} = toRefs(states)
const vm = getCurrentInstance().proxy
const key = (vm as unknown as SelectOptionProxy).value
select.onOptionCreate(vm as unknown as SelectOptionProxy)
onBeforeUnmount(() => {
const { selected } = select
let selectedOptions = select.props.multiple ? selected : [selected]
const doesExist = select.cachedOptions.has(props.value)
const doesExist = select.cachedOptions.has(key)
const doesSelected = selectedOptions.some(item => {
return item.value === (vm as unknown as SelectOptionProxy).value
})
// if option is not selected, remove it from cache
if (doesExist && !doesSelected) {
select.cachedOptions.delete(props.value)
select.cachedOptions.delete(key)
}
select.onOptionDestroy(props.value)
select.onOptionDestroy(key)
})
function selectOptionClick() {