In Vuejs, I have a method named getUsers that takes an array as input and fetches user data from the database.
When calling it like this, it successfully returns the results:
this.getUsers(executives).then(
result => {
this.specifcExecs = result;
});
To avoid repetitive calls to getUsers with different inputs, I decided to create a common method to directly assign values to specific arrays, as shown below:
this.specifcExecs = this.populateList(executives);
populateList(list){
this.getUsers(list).then(
result=> {
console.log("inside result in", result);
return result;
});
},
However, when trying to print this.specifcExecs, I receive undefined. Can someone help me understand what I am doing wrong here? I am looking for a way to efficiently handle promises and prevent code duplication.