Using Vue apex charts, i need to access the vue "this" context inside the function. the chart events functions set the "this" keyword to the function scope and i cant figure out how to access the vue "this"
events: {
dataPointSelection(event, chartContext, config) {
// how to use this within an event function?
this.vueData = event
}
},
I was able to workaround with this, does anyone have a better method?
mounted() {
const that = this
this.$refs.chart.updateOptions({
chart: {
events: {
dataPointSelection(event, chartContext, config) {
that.selectedDate = event
}
}
}
})
},
Use an arrow function
mounted() {
this.$refs.chart.updateOptions({
chart: {
events: {
dataPointSelection: (event, chartContext, config) => {
// you can call Vue methods now as "this" will point to the Vue instance when you use ES6 arrow function
}
}
}
})
}
Most helpful comment
Use an arrow function