mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
fix(components): [select] Filter duplicate emits of "update options" (#11884)
* fix(components): [select] Filter duplicate emits of "update options" * perf(components): [select] Code standardization
This commit is contained in:
@@ -6,6 +6,18 @@ export default defineComponent({
|
||||
name: 'ElOptions',
|
||||
emits: ['update-options'],
|
||||
setup(_, { slots, emit }) {
|
||||
let cachedOptions: any[] = []
|
||||
|
||||
function isSameOptions(a: any[], b: any[]) {
|
||||
if (a.length !== b.length) return false
|
||||
for (const [index] of a.entries()) {
|
||||
if (a[index] != b[index]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
return () => {
|
||||
const children = slots.default?.()!
|
||||
|
||||
@@ -19,7 +31,10 @@ export default defineComponent({
|
||||
)
|
||||
.map((item: VNode) => item.props?.label)
|
||||
|
||||
emit('update-options', filteredOptions)
|
||||
if (!isSameOptions(filteredOptions, cachedOptions)) {
|
||||
cachedOptions = filteredOptions
|
||||
emit('update-options', filteredOptions)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user