element-plus/packages/hooks/use-prop/index.ts
2022-05-30 09:26:14 +08:00

8 lines
272 B
TypeScript

import { computed, getCurrentInstance } from 'vue'
import type { ComputedRef } from 'vue'
export const useProp = <T>(name: string): ComputedRef<T | undefined> => {
const vm = getCurrentInstance()!
return computed(() => (vm.proxy?.$props as any)[name] ?? undefined)
}