1

My project saves users' profile images path in the database as varchar which is transfer into String in the backend and use JSON to send it to the frontend. How can I use this string to display an image by Vue?

Here you can see: Image URL can be received as a "string" by frontend correctly

I have tried for

<img class="user-profile-image" v-bind:src=userProfileImagePath>
<img class="user-profile-image" :src=userProfileImagePath>
<img class="user-profile-image" src=userProfileImagePath>
<img class="user-profile-image" src="userProfileImagePath">

But they all didn't work. How can I do?

2
  • Does it log any errors? Commented Feb 21, 2021 at 18:41
  • 2
    Please show the rest of the component template surrounding the <img> Commented Feb 21, 2021 at 19:04

2 Answers 2

1

Here you go

new Vue({
  el: "#app",
  data: {
    imageUri: ""
  },
  methods: {
    loadIcon() {
      // You might want to load your data here
      this.imageUri = "https://cdn.sstatic.net/Img/unified/sprites.svg?v=fcc0ea44ba27"
    }
  },
  created() {
    this.loadIcon();
  }
})
#app {
  height: 60px;
  overflow: hidden;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

<div id="app">
  <img v-bind:src="imageUri" />
</div>

Sign up to request clarification or add additional context in comments.

Comments

0

use JSON.parse(image_string_path_here) then use this parse link in image

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.