PicList/src/renderer/utils/common.ts

25 lines
520 B
TypeScript
Raw Normal View History

import { isReactive, isRef, toRaw, unref } from 'vue'
/**
* get raw data from reactive or ref
*/
2023-01-07 07:45:01 -05:00
export const getRawData = (args: any): any => {
if (isRef(args)) {
return unref(args)
}
if (isReactive(args)) {
return toRaw(args)
}
if (Array.isArray(args)) {
return args.map(getRawData)
}
if (typeof args === 'object' && args !== null) {
const data = {} as Record<string, any>
for (const key in args) {
data[key] = getRawData(args[key])
}
return data
}
return args
}