Utilizing PHP with a MySQL database to present data on highcharts in vue.js, I have defined an array in the data section of the page like so to use for displaying the chart data:
data() {
return {
gaugeData2: [],
}
To retrieve the data from the database, I am using the axios.get function in this manner:
allRecords: function() {
axios
.get("http://localhost/contacts.php" + "?action=fetch-all")
.then(function(response) {
console.log(response.data);
var x = response.data;
console.log(typeof x);
this.gaugeData2.push(x);
console.log(this.gaugeData2);
})
.catch(function(error) {
console.log(error);
});
},
However, upon trying this method, I encounter an error in the console - "TypeError: Cannot read property 'gaugeData2' of undefined at eval (dashboard.v1.vue?88bf:1465)"
I came across information online suggesting that data in vue.js returns type object and my function is returning a value of type 'number', causing this error. I attempted to use JSON.parse to convert it into an object type, but to no avail. Any assistance would be greatly appreciated. Thank you in advance for your help.