[Vuejs]-FileReader method does not update data property (vue.js)

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);
}

Leave a comment