I'm calling a function that uses a person's user name to find the current User in my database. When I log the current user in my function, it works fine, but after that it says it null or undefined whenever i try to access it.
In my mounted:
mounted() {
this.getCurrentUser(this.currentUserName);
console.log(this.currentUser)
}
In my getCurrentUser():
getCurrentUser(currentUserName){
UserDataService.getCurrentUser(currentUserName)
.then(response => {
this.currentUser = response.data;
console.log(this.currentUser);
})
.catch(e => {
console.log(e);
});
}
In my UserDataService:
getCurrentUser(userName){
return http.get("/users?userName="+userName);
}
This is when it is logged inside of the getCurrentUser function
Otherwise, it is null after i LOG it in mounted().