ant-design-vue/components/_util/reactivePick.ts
bowen fdf76b9fb9
fix: use fromPairs replace Object.fromEntries (#5605)
* fix: use fromPairs replace Object.fromEntries

* fix: use lodash-es replace lodash
2022-05-20 16:19:14 +08:00

16 lines
427 B
TypeScript

import type { UnwrapRef } from 'vue';
import { reactive, toRef } from 'vue';
import fromPairs from 'lodash-es/fromPairs';
/**
* Reactively pick fields from a reactive object
*
* @see https://vueuse.js.org/reactivePick
*/
export function reactivePick<T extends object, K extends keyof T>(
obj: T,
...keys: K[]
): { [S in K]: UnwrapRef<T[S]> } {
return reactive(fromPairs(keys.map(k => [k, toRef(obj, k)]))) as any;
}