I'm currently working on fetching data using Axios requests and storing it in an array. Below is the code I have been using:
props: [
'products',
],
data: function () {
return {
algolia: '',
products_data : [],
};
},
mounted() {
this.products_data = this.products;
}
methods: {
find () {
let new_product = {};
axios.get('/product/find?barcode=' + this.barcode)
.then(function (res) {
new_product.name = resp.data.name
new_product.barcode = resp.data.barcode
new_product.unit = resp.data.unit
this.products_data.push(new_product);
})
.catch(function (err) {
console.log(err);
})
},
}
Encountering the error
Cannot read property 'products_data' of undefined
due to the line this.products_data.push(new_product);
. As a beginner in Vue, any assistance would be greatly appreciated.
Thanks