fix: select not update

pull/4258/head
tangjinzhou 2021-06-24 11:03:02 +08:00
parent 2e06d38aff
commit d58a5d8b12
3 changed files with 12 additions and 5 deletions

View File

@ -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();
}
});

View File

@ -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>
);

View File

@ -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 ===========================