Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/yutahaga/vue-media-breakpoints

A plugin of Vue that store current viewport size name.
https://github.com/yutahaga/vue-media-breakpoints

media-queries vue vue-plugin

Last synced: about 2 months ago
JSON representation

A plugin of Vue that store current viewport size name.

Awesome Lists containing this project

README

        

# vue-media-breakpoints

## Features

- Not using Vue's private API.
- Using Passive Event Listeners.
- You can use a custom debouncing function.

## Getting Started

### Install

```sh
npm i @yutahaga/vue-media-breakpoints -S
```

or

```sh
yarn add @yutahaga/vue-media-breakpoints
```

### Usage

When supporting SSR, avoid using `v-if` and use `v-show`.
Note that `v-show` does not support the `` element, nor does it work with `v-else`.

```js
import { install as MediaBreakPointsPlugin, BreakPointManager } from '@yutahaga/vue-media-breakpoints';
import debounce from 'lodash.debounce';
import Vue from 'vue';

const GRID_BREAKPOINTS = {
xs: 0,
sm: 576,
md: 768,
lg: 992,
xl: 1200,
};

Vue.use(MediaBreakPointsPlugin, {
breakPoints: GRID_BREAKPOINTS,
debounceFunction: debounce,
debounceInterval: 30,
});

const vm = new Vue({
el: '#app',
template: `


{{ $bp.name }}: {{ $bp.width }}px



This tag is displayed only when the viewport is md ~ xl.



This tag is displayed only when the viewport is xs ~ sm.



This tag is displayed only when the viewport is lg.



This tag is displayed only when the viewport is xs and xl.



This tag is displayed only when the viewport is between sm and lg. (sm <= ViewPort < lg)



This tag is displayed only when the viewport is sm or above.



This tag is displayed only when the viewport is sm or below.



`
});

declare module 'vue/types/vue' {
interface Vue {
$bp: BreakPointManager;
}
}
```