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>( export default function useMemo<T>(
getValue: () => T, getValue: () => T,
condition: any[], condition: any[],
shouldUpdate: (prev: any[], next: any[]) => boolean, shouldUpdate?: (prev: any[], next: any[]) => boolean,
) { ) {
const cacheRef: Ref<T> = ref(getValue() as any); const cacheRef: Ref<T> = ref(getValue() as any);
watch(condition, (pre, next) => { watch(condition, (next, pre) => {
if (shouldUpdate(pre, next)) { if (shouldUpdate) {
if (shouldUpdate(next, pre)) {
cacheRef.value = getValue();
}
} else {
cacheRef.value = getValue(); cacheRef.value = getValue();
} }
}); });

View File

@ -13,7 +13,10 @@ describe('AutoComplete with Custom Input Element Render', () => {
{ {
render() { render() {
return ( return (
<AutoComplete ref="component" dataSource={['12345', '23456', '34567']}> <AutoComplete
ref="component"
options={[{ value: '12345' }, { value: '23456' }, { value: '34567' }]}
>
<input /> <input />
</AutoComplete> </AutoComplete>
); );

View File

@ -82,7 +82,7 @@ const OptionList = defineComponent<OptionListProps, { state?: any }>({
const memoFlattenOptions = useMemo( const memoFlattenOptions = useMemo(
() => props.flattenOptions, () => props.flattenOptions,
[() => props.open, () => props.flattenOptions], [() => props.open, () => props.flattenOptions],
(prev, next) => next[0] && prev[1] !== next[1], next => next[0],
); );
// =========================== List =========================== // =========================== List ===========================