Given this Vue component that attaches a global event listener:
var app = new Vue({
data: {
foo: 0;
},
methods: {
handle: function(e) {
this.foo = 1; // this refers to handler, not app
}
},
mounted: function() {
window.addEventListener("keypress", this.handle);
}
});
What is the correct way to refer to this
from within the event handler in order to update the component state? Alternatively, is there a better way to set event handlers on the entire window
?