UNPKG

@fast-china/utils

Version:

Fast 工具库.

1 lines 1.21 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":[],"mappings":";;AAIa,MAAA,iBAAiB,CAAI,QAA0B;AAQrD,MAAM,WAAW,CACvB,OACA,UACA,mBAC0C;AAC1C,MAAI,CAAC,MAAO,QAAO,SAAS,OAAO,CAAG,EAAA;AAEtC,SAAO,SAAkC,MAAM;AACxC,UAAA,kBAAkB,WAAW,KAAK,UAAU,kBAAkB,CAAE,CAAA,IAAI,CAAC;AAC3E,WAAO,KAAK,OAAO,OAAO,KAAK,eAAe,CAAC;AAAA,EAAA,CAC/C;AACF;"}