mirror of
https://github.com/continew-org/continew-admin-ui.git
synced 2025-09-13 02:57:11 +08:00
first commit
This commit is contained in:
24
src/hooks/modules/useBreakpointIndex.ts
Normal file
24
src/hooks/modules/useBreakpointIndex.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { useBreakpoint } from '@/hooks'
|
||||
|
||||
type BreakpointMap = {
|
||||
xs: number
|
||||
sm: number
|
||||
md: number
|
||||
lg: number
|
||||
xl: number
|
||||
xxl: number
|
||||
}
|
||||
|
||||
export function useBreakpointIndex(callback: (v: number) => void, breakpointObj?: BreakpointMap) {
|
||||
const { breakpoint } = useBreakpoint()
|
||||
|
||||
watch(
|
||||
() => breakpoint.value,
|
||||
(v) => {
|
||||
const def = { xs: 0, sm: 0, md: 0, lg: 1, xl: 1, xxl: 2 }
|
||||
const obj = breakpointObj ? breakpointObj : def
|
||||
callback(obj[v as keyof typeof obj])
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
}
|
Reference in New Issue
Block a user