Reactive window size and media query states for VueJS. Supports your favourite UI framework grid breakpoints out of the box, and can be configured with any custom breakpoints.
Version 1 only supports Vue 2. Vue 3 is supported in the v2 branch
✅ - Reactive and debounced window innerWidth and innerHeight
✅ - Reactive media query states and device orientation
✅ - Detect touch screen capability
✅ - Breakpoints for most common ui frameworks provided out of the box: Tailwind, Bootstrap, Bulma, Foundation, Materialize, Semantic UI
✅ - SSR compatible with Nuxt module included
Use default breakpoints from one of the supported UI frameworks:
Tailwind (default)
Vue.use(VueScreen);
Vue.use(VueScreen, 'tailwind');
Bootstrap
Vue.use(VueScreen, 'bootstrap');
Bulma
Vue.use(VueScreen, 'bulma');
Foundation
Vue.use(VueScreen, 'foundation');
Materialize
Vue.use(VueScreen, 'materialize');
Semantic UI
Vue.use(VueScreen, 'semantic-ui');
Custom breakpoints:
Vue.use(VueScreen, {
sm: 480, // will be converted to 480pxmd: '47em',
lg: '1200px',
});
You can find default UI framework breakpoints here
Callbacks
You can provide callbacks to decorate the $screen object with custom properties.
They are similar to Vue computed properties, but they can only depend on the properties of the $screen object will be run every time the debounced window resize event is triggered
If you extend one of the default frameworks, breakpointsOrder is provided automatically.
API
Available properties on the $screen object:
width
Number
Alias of window.innerWidth
height
Number
Alias of window.innerHeight
touch
Boolean
Tells if touch events are supported
portrait
Boolean
Tells if the device is in portrait mode
landscape
Boolean
Tells if the device is in landscape mode
breakpoint
String
Returns the currently active breakpoint. If you use custom breakpoint names, you must provide the breakpointsOrder property.
config
Object
Access the configuration passed when registering the plugin.
<breakpoint key>
Boolean
Every breakpoint key specified in the configuration will be available as a boolean value indicating if the corresponding media query matches.
To view default breakpoint keys and values for each framework, click here.
<callback key>
Any
Every callback specified in the configuration will have a corresponding property indicating the result of the callback. Callbacks will be called on every debounced resize event.
Nuxt module
The library can be used directly as a Nuxt module, just add it to the module section in nuxt.config.js:
While this library has no problems with SSR, there are some caveats related to the fact that when performing SSR the server does not have a screen size.
Due to this, when performing SSR this library will always have a $screen object with the following properties:
{
width: 410,
height: 730,
touch: true,
portrait: true,
landscape: false,
breakpoint: '<first breakpoint returned by breakpointsOrder>',
}
These values are some sensible defaults to promote a mobile-first approach.
This behavior however can lead to hydration errors if you wanna conditionally render a component based on one of the $screen properties:
When performing SSR, the template will be compiled into <div><!----></div>.
When rendering the component on a browser with a width that matches the $screen.lg condition, the template will be compiled into <div><MyComponent /></div>.
This will make Vue generate a warning in the console.
To read more about this topic you can check out this issue.
Reactive screen size and media query states for Vue. Integrates with most UI frameworks out of the box.
The npm package vue-screen receives a total of 0 weekly downloads. As such, vue-screen popularity was classified as not popular.
We found that vue-screen demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 0 open source maintainers collaborating on the project.
Package last updated on 01 Oct 2021
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.