I am exploring ways to create a method that can efficiently load and assign JSON files to dynamic variables. Despite my efforts, varA and varB are not being populated as expected:
data() {
return {
varA: Array,
varB: Array
}
},
mounted(){
this.loadJSON("example.com/fileA.json", this.varA);
this.loadJSON("example.com/fileB.json", this.varB);
},
methods: {
loadJSON(uri, target) {
fetch(uri)
.then(res => res.json())
.then((out) => {
target = out;
})
.catch(err => {
throw err;
});
},
}
I have also experimented with defining varA and varB as computed properties, but encountered the same issue. Is there a way to achieve this without explicitly specifying variable names in loadJSON()
?