Hello, I'm having an issue with using fetched data in a different method within VUE 3. My goal is to load all the data when the app starts and then be able to use it multiple times throughout the code. Here is my current code snippet:
const app = Vue.createApp({
data() {
return {
dataAll : [],
};
},
mounted() {
this.getData();
this.otherFunction();
},
methods: {
getData() {
fetch('app/api.php')
.then((response) => response.json())
.then((data) => {
this.dataAll = data;
//this.dataAll = JSON.parse(JSON.stringify(data));
});
},
otherFunction() {
console.log(this.dataAll);
}
});
However, the console is showing Proxy {} - Array(0)
. Can anyone point out where I might have made a mistake? Thanks.