Vue 2? you cannot define data like this. just add a computed property or a method to process the data.
Strongly suggest you use Vue 3.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I summarize my code as follows:
data () {
return {
currencyChart: 'USD',
chartOptions: {
tooltip: {
formatter: function() { // Add the formatter function**
const date = new Date(this.x);
const preco = Number(this.y).toLocaleString('pt-BR', { style: 'currency', currency: this.currencyChart });
return date.toLocaleDateString() + '<br> <span style="margin-top: 10px;"> ' +preco +'</span>';
}
},
}
}
},
I need to get the currencyChart, but if I put this.currencyChart, because I am using a function it refers to the content of the function.
If I change the function to arrow: formatter: () => {} , then it works, but this.x and this.y are no longer part of the chart values.
I've never come across this situation and I don't know how to resolve it or the best way. I appreciate any help.
@mvnobrega Check this page from vue docs for more info: https://vuejs.org/guide/extras/composition-api-faq.html
Also google it, you'll find a lot of info about this. In my opinion this is the best way to work with Vue.
Please or to participate in this conversation.