vite-vue3-lowcode/src/visual-editor/utils/useDotProp.ts

19 lines
429 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @name: useDotProp
* @author: 卜启缘
* @date: 2021/5/2 19:54
* @descriptionuseDotProp
* @update: 2021/5/2 19:54
*/
export const useDotProp = (originObj, propName) => {
const props: string[] = propName.split('.')
const isDotProp = props.length > 1
const prop = props.pop()!
const propObj = props.reduce((prev, curr) => (prev[curr] ??= {}), originObj)
return {
prop,
propObj,
isDotProp
}
}