I have a very simple app, that has 2 components: the App.vue
and another component, Home.vue
where I hold the rest of the structure of the app: a stick
You can use the mounted()
method to add your event listener to the window object like this:
var p = new Vue({
el: "#app",
data(){
return {
windowTop: 0
};
},
mounted()
{
var that = this;
window.addEventListener("scroll", function(){
that.windowTop = window.scrollY;
});
},
template: "{{windowTop}}"
});