Starting with this tutorial, I implemented the following code snippet:
export default {
data(){
return {
width: 0,
height: 0,
}
},
methods: {
resizedWindow: _.throttle(this.reset, 200),
reset(){
this.width = window.innerWidth;
this.height = window.innerHeight;
}
},
mounted(){
this.reset();
window.addEventListener('resize', this.resizedWindow);
}
}
However, an error message popped up stating:
Uncaught TypeError: Cannot read property 'reset' of undefined
Typically, this issue is related to how this
is handled and can be fixed by doing something like this:
// Replace previous resizeWindow method with...
resizedWindow(){
let vm = this;
_.throttle(vm.reset, 200);
},
Unfortunately, this modification doesn't trigger the reset
method. It seems like there might be a simple solution or a misunderstanding regarding this
– how can I correctly implement this functionality?