Two functions are used to load components for a page and save them in two fields - representatives and allUsers. An additional function, subtractSets(), is then used to modify the loaded data slightly. The issue arises when these fields (representatives and allUsers) are not initialized within this additional function. How can I ensure that the loaded data is accessible within subtractSets()?
setup() {
const representatives = ref([])
const allUsers = ref([])
return {
representatives,
users
}
},
methods(): {
loadUsersRepresentatives() {
axios.get('getRepresentatives').then(res => {
this.representatives = res.data
}).catch(() => {
...
});
},
loadAllUsers() {
axios.get('/getAllUsers').then(res => {
this.allUsers = res.data
}).catch(() => {
...
});
},
subtractSets(obj1, obj2) {
// manipulation logic here
},
showRepresentativesDialog(facultyID) {
this.loadUsersRepresentatives(facultyID)
this.loadAllUsers()
this.subtractSets(this.representatives, this.allUsers)
this.representativesDialog = true
}
},