useBreakpoints
The useBreakpoints composable provides comprehensive responsive design capabilities through reactive viewport dimension detection. It automatically tracks window size changes and provides boolean flags for current breakpoint ranges, enabling mobile-first and responsive layouts.
Installation
Install the Breakpoints plugin in your app’s entry point:
main.ts
import { createApp } from 'vue'
import { createBreakpointsPlugin } from '@vuetify/v0'
import App from './App.vue'
const app = createApp(App)
app.use(
createBreakpointsPlugin({
mobileBreakpoint: 'sm',
breakpoints: {
xs: 0,
sm: 680,
md: 1024,
lg: 1280,
xl: 1920,
xxl: 2560,
},
})
)
app.mount('#app')Usage
Once the plugin is installed, use the useBreakpoints composable in any component:
UseBreakpoints
<script setup lang="ts">
import { useBreakpoints } from '@vuetify/v0'
const breakpoints = useBreakpoints()
</script>
<template>
<div>
<nav v-if="breakpoints.mdAndUp">
<!-- Desktop navigation -->
</nav>
<nav v-else>
<!-- Mobile navigation -->
</nav>
<p v-if="breakpoints.isMobile">Mobile layout active</p>
<p>Current breakpoint: {{ breakpoints.name }}</p>
<p>Viewport: {{ breakpoints.width }} x {{ breakpoints.height }}</p>
</div>
</template>Architecture
useBreakpoints uses the plugin pattern with viewport observation:
The following API details are for the useBreakpoints composable.
Functions
createBreakpointsContext
(_options?: BreakpointsContextOptions) => ContextTrinity<E>Creates a new breakpoints context.
createBreakpointsPlugin
(_options?: BreakpointsPluginOptions) => anyCreates a new breakpoints plugin.
Options
namespace
stringmobileBreakpoint
number | BreakpointNamebreakpoints
Partial<Record<BreakpointName, number>>Properties
breakpoints
Readonly<Record<BreakpointName, number>>name
Readonly<ShallowRef<BreakpointName>>width
Readonly<ShallowRef<number>>height
Readonly<ShallowRef<number>>isMobile
Readonly<ShallowRef<boolean>>xs
Readonly<ShallowRef<boolean>>sm
Readonly<ShallowRef<boolean>>md
Readonly<ShallowRef<boolean>>lg
Readonly<ShallowRef<boolean>>xl
Readonly<ShallowRef<boolean>>xxl
Readonly<ShallowRef<boolean>>smAndUp
Readonly<ShallowRef<boolean>>mdAndUp
Readonly<ShallowRef<boolean>>lgAndUp
Readonly<ShallowRef<boolean>>xlAndUp
Readonly<ShallowRef<boolean>>xxlAndUp
Readonly<ShallowRef<boolean>>smAndDown
Readonly<ShallowRef<boolean>>mdAndDown
Readonly<ShallowRef<boolean>>lgAndDown
Readonly<ShallowRef<boolean>>xlAndDown
Readonly<ShallowRef<boolean>>xxlAndDown
Readonly<ShallowRef<boolean>>Methods
update
() => voidWas this page helpful?
