Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
VueJS images from json won´t render

I´ve got a JSON file like this:

"images": {
      "thumbnail": "./assets/starry-night/thumbnail.jpg",
      "hero": {
        "small": "./assets/starry-night/hero-small.jpg",
        "large": "./assets/starry-night/hero-large.jpg"
      },
      "gallery": "./assets/starry-night/gallery.jpg"
    }

My code in Vue is:

<img
          v-bind:src="data.images.thumbnail"
          alt=""
          srcset=""
          height="100px"
          width="100px"
        />

And it "works", it gives back an IMG. But the path of the image is ./assets/starry-night/gallery.jpg and I think that´s why it won´t load.

Do I have to trick the router or anything?

./assets/starry-night/gallery.jpg

Output in Chrome.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Your data is treated as a string, therefore it's looking for the path which of course doesn't exists. Just define a const publicUrl = 'http://mysite.test/' somewhere to complete the image URL such as

<img
    v-bind:src="publicUrl + data.images.thumbnail"
    alt=""
    srcset=""
    height="100px"
    width="100px"
/>

In addition, you can reference a folder by doing

<img src="@/assets/starry-night/thumbnail.jpg"/>
about 4 years ago · Juan Pablo Isaza Report

0

Solved with:

 created() {
    this.publicURL = "https://6e222.csb.app";
  },

And moved assets/xxx/ to PUBLIC folder instead of in SRC.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!