UNPKG

@fast-china/utils

Version:

Fast 工具库.

1 lines 1.25 kB
{"version":3,"file":"props.mjs","sources":["../../../../src/vue/props.ts"],"sourcesContent":["import { computed } from \"vue\";\nimport { omit, pick } from \"lodash-unified\";\nimport type { ComputedRef, PropType } from \"vue\";\n\nexport const definePropType = <T>(val: any): PropType<T> => val;\n\n/**\n * 构建 props\n * @param props props\n * @param rawProps 原生 props\n * @param ignoreRawProps 忽略 原生 props 的 key\n */\nexport const useProps = <T extends Record<string, unknown>, RT extends Record<string, unknown>>(\n\tprops: T,\n\trawProps?: RT,\n\tignoreRawProps?: (keyof RT)[]\n): ComputedRef<Record<string, unknown>> => {\n\tif (!props) return computed(() => ({}));\n\n\treturn computed<Record<string, unknown>>(() => {\n\t\tconst omittedRawProps = rawProps ? omit(rawProps, ignoreRawProps ?? []) : {};\n\t\treturn pick(props, Object.keys(omittedRawProps)) as Record<string, unknown>;\n\t});\n};\n"],"names":["definePropType","val","useProps","props","rawProps","ignoreRawProps","computed","omittedRawProps","omit","pick","Object","keys"],"mappings":"+EAIO,MAAMA,EAAqBC,GAA0BA,EAQ/CC,EAAW,CACvBC,EACAC,EACAC,IAIOC,EAFFH,EAEoC,KACxC,MAAMI,EAAkBH,EAAWI,EAAKJ,EAAUC,GAAkB,IAAM,CAAA,EAC1E,OAAOI,EAAKN,EAAOO,OAAOC,KAAKJ,KAJJ,KAAA,CAAO"}