I'm working on a chat system, each message belongs to a user, who sent it . In the database of messages I store just the user id, and I have a problem with fetching the users names, and replace it in the message.
This is the way I tried to fetch the username, by creating a method which takes the users id, and after fetching from api returns the users name, but the return doesn't work :
<div v-for="message in messages" :key="message.id" class="message">
   <a href="#">@{{ getUserDetails(message.user_id) }}</a>
   <p>@{{ message.message }}</p>
</div>
    methods: {
        getUserDetails(id) {
            fetch('/api/user/' + id)
                .then(res => res.json())
                .then(res => {
                    return res.name;
                })
        }
    },
I hope you understand my problem, sorry for my bad english, is not my native language ...
 
    