Skip to content

Instantly share code, notes, and snippets.

@alejandroiglesias
Forked from pxwee5/WindowInstanceMap.js
Last active February 18, 2019 20:03
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 alejandroiglesias/c4721d23aa5f777fcaf80a1d4cf5c0f4 to your computer and use it in GitHub Desktop.
Save alejandroiglesias/c4721d23aa5f777fcaf80a1d4cf5c0f4 to your computer and use it in GitHub Desktop.
Reactive Window Parameters in Vue.js - Adapted from: https://blog.usejournal.com/reactive-window-parameters-in-vuejs-fc5de75d7ab5
import Vue from 'vue'
export default class extends Vue {
constructor() {
super({
data() {
return {
scrollY: 0
}
},
created() {
window.addEventListener('scroll', e => {
this.scrollY = window.scrollY
})
},
})
}
}
@alejandroiglesias
Copy link
Author

This version of WindowInstanceMap.js from James Wee requires you to instantiate the class so that you don't have seemingly unused imports:

// App.js
import WindowInstanceMap from './WindowInstanceMap.js'
new WindowInstanceMap()

This would make it a much preferred solution since seemingly unused imports can be removed either by automatic processes or human beings unaware of the details of the import.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment