7👍
✅
You’re right, it’s not being updated. The context of this
within an anonymous function
changes.
reader.onload = function(event) {
this.json = JSON.parse(event.target.result);
}.bind(this);
In your case you can simply just use the bind
method.
If you’re transpiling downwards anyway, you can use the fat arrow
method:
reader.onload = (event) => {
this.json = JSON.parse(event.target.result);
}
Source:stackexchange.com