Hello Stefan!
You're on the right track with using arrow functions to maintain the this context of the Vue component inside the event handler. To access both the Vue instance's data and the image's properties, you can use a separate variable to reference the Vue instance's this inside the onload function. Here's how you can do it:
export default {
data: function() {
return {
logo_height: null,
}
},
mounted() {
const vm = this; // Store the Vue instance's 'this' in a variable
const image = new Image();
image.onload = function() {
// 'this' refers to the image here
console.log("height", this.height);
// 'vm' refers to the Vue instance
vm.logo_height = this.height;
};
image.src = vm.fn_x200; // Assuming 'fn_x200' is a reactive data property or computed property
}
}
In the mounted hook, we store the Vue instance's this in a variable called vm. Inside the onload function, this refers to the image, so we can access its height. We then set the logo_height property of the Vue instance using vm.logo_height = this.height.
This way, you can access both the Vue instance and the image properties where needed.