AlexandreBonaventure / Vue Mq

Licence: mit
📱 💻 Define your breakpoints and build responsive design semantically and declaratively in a mobile-first way with Vue.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vue Mq

One
基于Spring Boot和Vue2开发的前后端分离的后台管理系统
Stars: ✭ 426 (-10.13%)
Mutual labels:  vuejs2
Luban H5
[WIP]en: web design tool || mobile page builder/editor || mini webflow for mobile page. zh: 类似易企秀的H5制作、建站工具、可视化搭建系统.
Stars: ✭ 4,991 (+952.95%)
Mutual labels:  vuejs2
Flutter Assetsaudioplayer
Play simultaneously music/audio from assets/network/file directly from Flutter, compatible with android / ios / web / macos, displays notifications
Stars: ✭ 458 (-3.38%)
Mutual labels:  media
Vuet
允许你定义飙车过程的集中式状态管理模式
Stars: ✭ 430 (-9.28%)
Mutual labels:  vuejs2
Web Performance Monitoring System
A complete performance monitoring system.
Stars: ✭ 436 (-8.02%)
Mutual labels:  vuejs2
Vue Touch Ripple
👆 Touch ripple component for @vuejs
Stars: ✭ 443 (-6.54%)
Mutual labels:  vuejs2
Sonatamediabundle
Symfony SonataMediaBundle
Stars: ✭ 415 (-12.45%)
Mutual labels:  media
Laravel Medialibrary
Associate files with Eloquent models
Stars: ✭ 4,743 (+900.63%)
Mutual labels:  media
Vue Area Linkage
省市区联动选择: https://dwqs.github.io/vue-area-linkage/
Stars: ✭ 439 (-7.38%)
Mutual labels:  vuejs2
Vue Swatches
🎨 Help the user picking beautiful colors!
Stars: ✭ 456 (-3.8%)
Mutual labels:  vuejs2
Imagestore
Open source google photos alternative!
Stars: ✭ 429 (-9.49%)
Mutual labels:  media
Vue Gl
Vue.js components rendering 3D WebGL graphics reactively with three.js
Stars: ✭ 434 (-8.44%)
Mutual labels:  vuejs2
Vue Drag Drop
A lightweight Vue wrapper that abstracts away the wonkier parts of the Drag and Drop Browser API
Stars: ✭ 444 (-6.33%)
Mutual labels:  vuejs2
Styled Breakpoints
Simple and powerful tool for creating breakpoints in styled components and emotion. 💅
Stars: ✭ 428 (-9.7%)
Mutual labels:  media
Vue Boilerplate Template
🍎 Efficient development of web SPA using Vue.js(2.*) + Webpack + Element-ui + Pwa + Vuex + Vuex-router + Vue-i18n + Dayjs + Lodash.
Stars: ✭ 461 (-2.74%)
Mutual labels:  vuejs2
Vue Json Tree View
A JSON Tree View Component for Vue.js
Stars: ✭ 418 (-11.81%)
Mutual labels:  vuejs2
H5
📃an app which automatically generates HTML5 files.
Stars: ✭ 441 (-6.96%)
Mutual labels:  vuejs2
Douban
Douban book website demo by server side render
Stars: ✭ 468 (-1.27%)
Mutual labels:  vuejs2
Yasea
RTMP live streaming client for Android
Stars: ✭ 4,557 (+861.39%)
Mutual labels:  media
Vue Chartjs
📊 Vue.js wrapper for Chart.js
Stars: ✭ 4,554 (+860.76%)
Mutual labels:  vuejs2

Vue MQ (MediaQuery)

Define your breakpoints and build responsive design semantically and declaratively in a mobile-first way with Vue.

_Use with vue: ^2.x.x _

Demo: here

Table of Contents

Installation

Using NPM

npm install vue-mq

Using Yarn

yarn add vue-mq

Usage

1. Install plugin

Define your custom breakpoints by passing breakpoints option. This let you name the breakpoints as you want Eg: { phone: 500, tablet: 1200, other: Infinity } { small: 500, large: 1200, whatever: Infinity } { xs: 300, s: 500, m: 800, l: 1200, xl: Infinity }

import Vue from 'vue'
import VueMq from 'vue-mq'

Vue.use(VueMq, {
  breakpoints: { // default breakpoints - customize this
    sm: 450,
    md: 1250,
    lg: Infinity,
  }
  defaultBreakpoint: 'sm' // customize this for SSR
})

Use $mq property

After installing the plugin every instance of Vue component is given access to a reactive $mq property. Its value will be a String which is the current breakpoint.

Eg: (with default breakpoints) 'sm' => 0 > screenWidth < 450 'md' => 450 >= screenWidth < 1250 'lg' => screenWidth >= 1250

//Use it in a component
new Vue({
  template: `
    <h1>current: {{$mq}}</h1>
  `,
})

Use $mq property with the mq filter

Using the filter allow to build your responsive design in a declarative way. This can be very useful and elegant to pass down props to layout component. (eg: a grid system)

new Vue({
  template: `
    <grid-component :column="$mq | mq({ sm: 1, md: 2, lg: 3 })">
    </grid-component>
  `,
})

Remember that the filter design embrace mobile-first philosophy so writing $mq | mq({ sm: 1, lg: 3 }) will output 1 for md breakpoint if omited. In short it will always fallback to the smallest breakpoint (aka mobile) if value isn't overriden by a largest breakpoint.

Use $mq with a computed property

$mq property is fully reactive (like a data property) so feel free to use it in a computed.

new Vue({
  computed: {
    displayText() {
      return this.$mq === 'sm' ? 'I am small' : 'I am large'
    }
  },
  template: `
    <h1>{{displayText}}</h1>
  `,
})

MqLayout component

In addition to $mq property this plugin provide a wrapper component to facilitate conditional rendering with media queries.

Usage:

<mq-layout mq="lg">
  <span> Display on lg </span>
</mq-layout>
<mq-layout mq="md+">
  <span> Display on md and larger </span>
</mq-layout>
<mq-layout :mq="['sm', 'lg']">
  <span> Display on sm and lg </span>
</mq-layout>

Props mq => required : String | Array

Important: note that you can append a + modifier at the end of the string to specify that the conditional rendering happens for all greater breakpoints.

SSR Support

v1.0+ now supports SSR. You can customize the defaultBreakpoint which let you set the breakpoint used by the server-side-rendering

Browser Support

This plugin relies on matchMedia API to detect screensize change. So for older browsers and IE, you should polyfill this out: Paul Irish: matchMedia polyfill

Support

Please open an issue for support.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].