1

I'm using Vue 3.2.13 version. I am using Avatars by DiceBear for my application for users' profile pictures.
The URL for the GET endpoint is:
https://avatars.dicebear.com/v2/avataaars/{{username}}.svg?options[mood][]=happy

Here each string generates a unique image and I use the username to generate a unique avatar for each user. The {username} in the URL is the placeholder for the user's username. It should be dynamically replaced by the username received from the user's API endpoint.
So the sample UI should be like the following;
sample UI
But I get the same image for different usernames. But other fetched data properly placed. Here is the UI I got.
my UI
Here is my code;

<div class="card" style="width: 18rem" v-for="(person, key) in people" :key="key">
          <img class="card-img-top" src="https://avatars.dicebear.com/v2/avataaars/{{person.username}}.svg?options[mood][]=happy" alt="Card image cap" />
          <h5 class="card-title">
            {{ person.name }}
          </h5>
          <div class="card-text">
            <i class="fa-solid fa-envelope"> </i>
            <p class="icon">
              {{ person.email }}
            </p>
            <br />

            <i class="fa-solid fa-phone"></i>
            <p class="icon">
              {{ person.phone }}
            </p>
            <br />
created: async function () {
    try {
      this.loading = true;
      let response = await UserService.getAllUsers();
      this.people = response.data;
      this.loading = false;
    } catch (error) {
      this.errorMessage = error;
      this.loading = false;
    }
  },

Thank you.

1 Answer 1

3

Bind it using string template `` :

:src="`https://avatars.dicebear.com/v2/avataaars/${person.username}.svg?options[mood][]=happy`"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.