Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda