Im using parse.js for pulling data from database in SPA build in Quasar (based on vue.js). Im getting data undefined when fetching data from my database when calling the data through a method but it works when I put it straight into the create function. I guess they might be in different scopes (?) but I cannot figure out why.
This works:
export default {
name: "MyPage",
data() {
return {
myData: []
};
},
created: async function() {
let query = new parse.Query("TheData");
const results = await query.find();
this.myData = results;
console.log(this.myData);
}
But when I encapsulate the data into a method it returns
TypeError: Cannot set property 'myData' of undefined
export default {
name: "MyPage",
data() {
return {
myData: []
};
},
created: async function() {
this.getTheData();
},
methods: {
getTheData: async () => {
let query = new parse.Query("TheData");
const results = await query.find();
this.myData = results; // TypeError: Cannot set property 'myData' of undefined
console.log(this.myData);
},