import type { App, Plugin } from 'vue' /** * * @param component 需要注册的组件 * @param alias 组件别名 * @returns any */ export const withInstall = (component: T, alias?: string) => { const comp = component as any comp.install = (app: App) => { app.component(comp.name || comp.displayName, component) if (alias) { app.config.globalProperties[alias] = component } } return component as T & Plugin } /** * @param str 需要转下划线的驼峰字符串 * @returns 字符串下划线 */ export function humpToUnderline(str: string): string { return str.replace(/([A-Z])/g, '-$1').toLowerCase() } /** * @param str 需要转驼峰的下划线字符串 * @returns 字符串驼峰 */ export function underlineToHump(str: string): string { return str.replace(/\-(\w)/g, function (_, letter: string) { return letter.toUpperCase() }) } export function setCssVar(prop: string, val: any, dom = document.documentElement) { dom.style.setProperty(prop, val) }