There seems to be an issue with my function that utilizes a person's user name to retrieve the current User from the database. Initially, when I log the current user within the function, everything works perfectly. However, once I attempt to access it afterwards, it either shows as null or undefined.
Within my mounted method:
mounted() {
this.getCurrentUser(this.currentUserName);
console.log(this.currentUser)
}
Here is the code for getCurrentUser():
getCurrentUser(currentUserName){
UserDataService.getCurrentUser(currentUserName)
.then(response => {
this.currentUser = response.data;
console.log(this.currentUser);
})
.catch(e => {
console.log(e);
});
}
In my UserDataService class:
getCurrentUser(userName){
return http.get("/users?userName="+userName);
}
You can see a screenshot of when it is logged inside the getCurrentUser function here
However, outside of the function, it appears as null whenever I log it in mounted().