fix: select not update
parent
2e06d38aff
commit
d58a5d8b12
|
@ -3,11 +3,15 @@ import { Ref, ref, watch } from 'vue';
|
|||
export default function useMemo<T>(
|
||||
getValue: () => T,
|
||||
condition: any[],
|
||||
shouldUpdate: (prev: any[], next: any[]) => boolean,
|
||||
shouldUpdate?: (prev: any[], next: any[]) => boolean,
|
||||
) {
|
||||
const cacheRef: Ref<T> = ref(getValue() as any);
|
||||
watch(condition, (pre, next) => {
|
||||
if (shouldUpdate(pre, next)) {
|
||||
watch(condition, (next, pre) => {
|
||||
if (shouldUpdate) {
|
||||
if (shouldUpdate(next, pre)) {
|
||||
cacheRef.value = getValue();
|
||||
}
|
||||
} else {
|
||||
cacheRef.value = getValue();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -13,7 +13,10 @@ describe('AutoComplete with Custom Input Element Render', () => {
|
|||
{
|
||||
render() {
|
||||
return (
|
||||
<AutoComplete ref="component" dataSource={['12345', '23456', '34567']}>
|
||||
<AutoComplete
|
||||
ref="component"
|
||||
options={[{ value: '12345' }, { value: '23456' }, { value: '34567' }]}
|
||||
>
|
||||
<input />
|
||||
</AutoComplete>
|
||||
);
|
||||
|
|
|
@ -82,7 +82,7 @@ const OptionList = defineComponent<OptionListProps, { state?: any }>({
|
|||
const memoFlattenOptions = useMemo(
|
||||
() => props.flattenOptions,
|
||||
[() => props.open, () => props.flattenOptions],
|
||||
(prev, next) => next[0] && prev[1] !== next[1],
|
||||
next => next[0],
|
||||
);
|
||||
|
||||
// =========================== List ===========================
|
||||
|
|
Loading…
Reference in New Issue