mirror of
https://github.com/element-plus/element-plus.git
synced 2024-11-27 02:01:15 +08:00
fix(components): [select-v2] label display error when re-rendering (#18128)
* fix(components): [select-v2] label display error when re-rendering * fix: update
This commit is contained in:
parent
1d26af3066
commit
c4f7e27bdd
@ -716,7 +716,7 @@ const useSelect = (props: ISelectV2Props, emit) => {
|
||||
menuRef.value.scrollToItem(index)
|
||||
}
|
||||
|
||||
const getOption = (value) => {
|
||||
const getOption = (value: any, cachedOptions?: Option[]) => {
|
||||
// match the option with the given value, if not found, create a new option
|
||||
const selectValue = getValueKey(value)
|
||||
|
||||
@ -725,6 +725,15 @@ const useSelect = (props: ISelectV2Props, emit) => {
|
||||
|
||||
return option
|
||||
}
|
||||
if (cachedOptions && cachedOptions.length) {
|
||||
const option = cachedOptions.find(
|
||||
(option) => getValueKey(getValue(option)) === selectValue
|
||||
)
|
||||
if (option) {
|
||||
return option
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
[aliasProps.value.value]: value,
|
||||
[aliasProps.value.label]: value,
|
||||
@ -734,11 +743,12 @@ const useSelect = (props: ISelectV2Props, emit) => {
|
||||
const initStates = () => {
|
||||
if (props.multiple) {
|
||||
if ((props.modelValue as Array<any>).length > 0) {
|
||||
const cachedOptions = states.cachedOptions.slice()
|
||||
states.cachedOptions.length = 0
|
||||
states.previousValue = props.modelValue.toString()
|
||||
|
||||
for (const value of props.modelValue) {
|
||||
const option = getOption(value)
|
||||
const option = getOption(value, cachedOptions)
|
||||
states.cachedOptions.push(option)
|
||||
}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user