[Chartjs]-How to access data outside the onclick function

1👍

In onClick: function(evt, array) { }, this is the Chart instance. To bind the context to the Vue instance, use an arrow function:

this._chart = new Chart({
  onClick: (evt, array) => {
    ...
    console.log(this.id[position])
  }
)

updated fiddle

2👍

Use this when referring to a variable from your component’s data and props attribute.

So instead of:

window.open("/#/user/history/detail/" + id[position], "_self");

Use:

window.open("/#/user/history/detail/" + this.id[position], "_self");

Leave a comment