Vue 3 MQ (Media Query) Define your breakpoints and build responsive design semantically and declaratively in a mobile-first way with Vue 3.
Define your breakpoints and build responsive design semantically and declaratively in a mobile-first way with Vue 3.
Use with vue: ^3.x.x
Since Vue 3 has dropped support for filters, the previous functionality has been removed
Presently, support for SSR has been removed
See https://vue3-mq.info for a demonstration and usage guide for Vue3-MQ.
npm install vue3-mq
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 { createApp } from "vue";
import VueMq from "vue3-mq";
const app = createApp({});
app.use(VueMq, {
breakpoints: { // default breakpoints - customize this
sm: 450,
md: 1250,
lg: Infinity,
}
})
app.mount('#app');
$mq
global propertyAfter 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
<template>
<div>{{ $mq }}</div>
</template>
$mq
with a computed propertyThe $mq
property is fully reactive, so feel free to use it in a computed.
createApp({
computed: {
displayText() {
return this.$mq === 'sm' ? 'I am small' : 'I am large'
}
},
template: `
<h1>{{displayText}}</h1>
`,
})
A function is available via Vue's provide
method which allows you to dynamically change the breakpoints which are responded to. Simply inject
it into any component where it's needed.
import { inject, onMounted } from "vue";
setup() {
const updateBreakpoints = inject("updateBreakpoints");
onMounted() {
updateBreakpoints({
xs: 576,
sm: 768,
md: 992,
lg: 1200,
xl: 1400,
xxl: Infinity
})
}
}
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']" tag="span">
Display on sm and lg
</mq-layout>
Props
mq
=> required : [String,Array] - see below
tag
=> optional : String - sets the HTML tag to use for the rendered component (default 'div')
Appending a +
to your mq property will make the component render on that breakpoint and any above
<mq-layout mq="lg+" tag="span">I will render on large and above screen sizes</mq-layout>
Appending a -
to your mq property will make the component render on that breakpoint and any below
<mq-layout mq="md-" tag="span">I will render on medium and below screen sizes</mq-layout>
Placing a -
between two breakpoints in your mq property will make the component render on any breakpoints in that range
<mq-layout mq="sm-lg">I will render on small, medium and large screen sizes</mq-layout>
This plugin relies on matchMedia API to detect screen size change. So for older browsers and IE, you should polyfill this out: Paul Irish: matchMedia polyfill
Please open an issue for support.
Author: craigrileyuk
Demo: https://craigriley.uk/
Source Code: https://github.com/craigrileyuk/vue3-mq
In this article, we are going to list out the most popular websites using Vue JS as their frontend framework. Vue JS is one of those elite progressive JavaScript frameworks that has huge demand in the web development industry. Many popular websites are developed using Vue in their frontend development because of its imperative features.
Vue Native is a framework to build cross platform native mobile apps using JavaScript. It is a wrapper around the APIs of React Native. So, with Vue Native, you can do everything that you can do with React Native. With Vue Native, you get
In this article, you’ll learn how to build a Vue custom select component that can be easily be styled using your own CSS. In fact, it’s the same component that we use in production on Qvault, and you can see it in action on the playground.
There are plenty of libraries out there that will have you up and running with a good tooltip solution in minutes. However, if you are like me, you are sick and tired of giant dependency trees that have the distinct possibility of breaking at any time.
Vue-ShortKey - The ultimate shortcut plugin to improve the UX .Vue-ShortKey - plugin for VueJS 2.x accepts shortcuts globaly and in a single listener.