Skip to content

Instantly share code, notes, and snippets.

@samzeng
Last active April 11, 2019 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samzeng/c6ae6ca3c3270345d4b0149f8ead718c to your computer and use it in GitHub Desktop.
Save samzeng/c6ae6ca3c3270345d4b0149f8ead718c to your computer and use it in GitHub Desktop.
Vue get Window with and height
new Vue({
el: '#app',
data: {
window: { width: 0, height: 0 }
},
created() {
window.addEventListener('resize', this.handleResize)
this.handleResize();
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
methods: {
handleResize() {
this.window.width = window.innerWidth;
this.window.height = window.innerHeight;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment