Created
July 1, 2019 14:46
-
-
Save viniazvd/ebf8bfd78b93cbde2c543e01e28ff805 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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