Skip to content

vuex-breakpoint is a Vue.js plugin to get the media query changes in a vue application.

Notifications You must be signed in to change notification settings

patrikkarlsson/vuex-breakpoint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vuex-breakpoint

vuex-breakpoint is a Vue.js plugin to get the media query changes in a vue application.

Live demo

Edit Vue Template

Installation

yarn add vuex-breakpoint

Usage

Import and add breakpointStore to vuex store.

import Vue from 'vue';
import Vuex from 'vuex';
import { breakpointStore } from 'vuex-breakpoint';

Vue.use(Vuex);

export default new Vuex.Store({
 modules: {
	 breakpointStore,
 },
});

Import and add breakpoint as a mixin in App component.

import { breakpoint } from 'vuex-breakpoint';
export default {
	name: 'App',
	mixins: [
		breakpoint,
	],
}

Import breakpoint.scss and add different media queries and then pass them to breakpoints mixin.

@import "~vuex-breakpoint/src/scss/breakpoints";

$breakpoints: (
  ("thumb", 0px, 576px),
  ("handheld", 577px, 768px),
  ("lap", 769px, 992px),
  ("desktop", 993px, null)
);

@include breakpoints($breakpoints);

To get updates when media queries changes use the computed property.

<template>
  <h1>{{ currentBreakpoint }}</h1>
</template>

<script>
import { mapGetters } from 'vuex';

export default {
  name: 'YourComponent',
  computed: {
	  ...mapGetters( {
	    currentBreakpoint: 'breakpointStore/currentBreakpoint',
	} ),
  },
}
</script>

API

Computed properties

breakpointStore/currentBreakpoint a string which tells you which media query being used.

About

vuex-breakpoint is a Vue.js plugin to get the media query changes in a vue application.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published