Reactive Screen Size and Media Queries for Vue 3

2.4.2 · active · verified Sun Apr 19

VueScreen is a JavaScript library for Vue 3 that provides reactive access to window dimensions, media query states, and device orientation. It enables developers to easily integrate dynamic screen size information and breakpoint detection into their Vue applications. The current stable version is 2.4.2, and the project demonstrates an active release cadence with regular minor and patch updates, indicating ongoing maintenance and feature development. Key differentiators include its debounced reactive screen size updates, comprehensive media query state tracking, touch screen detection, and out-of-the-box support for popular UI framework breakpoints like Tailwind, Bootstrap, Bulma, Foundation, Materialize, and Semantic UI. It is also designed to be compatible with Server-Side Rendering (SSR) environments. Version 2.x of `vue-screen` specifically targets Vue 3 applications, with previous versions (v1.x) supporting Vue 2.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to use `vue-screen` with the Composition API to access reactive screen dimensions and grid breakpoints, and how to install it as a global plugin.

import { createApp } from 'vue'
import { useScreen, useGrid } from 'vue-screen'
import VueScreen from 'vue-screen'

const App = {
  setup() {
    const screen = useScreen();
    const grid = useGrid('tailwind'); // Or 'bootstrap', 'bulma', etc.

    return {
      screen,
      grid
    };
  },
  template: `
    <div>
      <h1>VueScreen Demo</h1>
      <p>Window Width: {{ screen.width }}px</p>
      <p>Window Height: {{ screen.height }}px</p>
      <p>Current Breakpoint: {{ grid.breakpoint }}</p>
      <p>Is Mobile: {{ grid.isMobile }}</p>
      <p>Is Desktop: {{ grid.isDesktop }}</p>
      <p>Orientation: {{ screen.orientation }}</p>
    </div>
  `
};

// Option 1: Using Composition API directly in a component (as shown above)
// Note: For global access or Options API, use as a plugin:
const app = createApp(App);
app.use(VueScreen, 'bootstrap'); // Installs as a plugin with Bootstrap breakpoints
app.mount('#app');

// You can inspect the global properties with Options API in a child component:
// <template>
//   <ul>
//     <li>Current breakpoint is: {{ $grid.breakpoint }}</li>
//     <li>Window width is: {{ $screen.width }}</li>
//   </ul>
// </template>

view raw JSON →