MatchMedia component library for Vue
The Vue Component Media Queries is a lightweight and user-friendly component library for Vue that allows you to define responsive breakpoints via media queries and use them in your components. It provides an integration with window.matchMedia for Vue, ensuring zero hydration errors and compatibility with server-side rendering. The library is clean and tree-shakeable, allowing you to import only the necessary components where needed.
<template>) or as an injected property (inside <script>).To install the Vue Component Media Queries library, you can use either NPM or a CDN.
Install the library as a dependency:
npm i vue-component-media-queries
Import the components via named exports where necessary in your project:
import { MediaQueryProvider, MatchMedia } from 'vue-component-media-queries';
If you don’t have the option to use NPM, you can use a CDN package. However, this method is not recommended for production usage. Prefer using the NPM method whenever possible.
Import the library after Vue from the CDN and get components from the global VueComponentMediaQueries object:
<script src="https://cdn.jsdelivr.net/npm/vue-component-media-queries@1.0.0/dist/vue-component-media-queries.min.js"></script>
<script>
const { MediaQueryProvider, MatchMedia } = VueComponentMediaQueries;
</script>
The Vue Component Media Queries library is a lightweight and user-friendly component library for Vue that allows you to define and use responsive breakpoints in your components. It provides easy integration with Vue, supports server-side rendering, and is clean and tree-shakeable. Whether you need to toggle element visibility or have logic bound to media queries, this library offers a simple and efficient solution.