gohttpdUi/src/utils/index.ts

41 lines
1016 B
TypeScript
Raw Normal View History

import type { App, Plugin } from 'vue'
/**
*
* @param component
* @param alias
* @returns any
*/
export const withInstall = <T>(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
}
2022-01-05 17:02:25 +08:00
/**
* @param str 线
* @returns 线
*/
export const humpToUnderline = (str: string): string => {
2022-01-05 17:02:25 +08:00
return str.replace(/([A-Z])/g, '-$1').toLowerCase()
}
/**
* @param str 线
* @returns
*/
export const underlineToHump = (str: string): string => {
return str.replace(/\-(\w)/g, (_, letter: string) => {
2022-01-05 17:02:25 +08:00
return letter.toUpperCase()
})
}
2022-01-13 17:26:06 +08:00
export const setCssVar = (prop: string, val: any, dom = document.documentElement) => {
2022-01-13 17:26:06 +08:00
dom.style.setProperty(prop, val)
}