Skip to content

Instantly share code, notes, and snippets.

@viniazvd
Created July 1, 2019 14:46
Show Gist options
  • Save viniazvd/ebf8bfd78b93cbde2c543e01e28ff805 to your computer and use it in GitHub Desktop.
Save viniazvd/ebf8bfd78b93cbde2c543e01e28ff805 to your computer and use it in GitHub Desktop.
export default {
data () {
return {
xsMobileMedia: window.matchMedia('(max-width: 576px)'),
mobileMedia: window.matchMedia('(max-width: 1023px)'),
isXsMobile: false,
isMobile: false,
}
},
methods: {
setBreakpoint () {
this.isMobile = this.mobileMedia && this.mobileMedia.matches
this.isXsMobile = this.xsMobileMedia && this.xsMobileMedia.matches
}
},
beforeDestroy () {
this.mobileMedia.removeListener(this.setBreakpoint)
this.xsMobileMedia.removeListener(this.setBreakpoint)
},
mounted () {
this.mobileMedia.addListener(this.setBreakpoint)
this.xsMobileMedia.addListener(this.setBreakpoint)
this.setBreakpoint()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment