Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

234
Vistas
Dynamic image source throws error in VueJs

👋 I'm having a problem: I'm trying to load an image path dynamically, like this:

<img :src="require(`@/assets/images/box-packaging-0@2x.png?format=${webPFormat('png')}&width=950&nearlossless=1&compression=4`)">

but I'm getting this error:

[Vue warn]: Error in render: "Error: Cannot find module './box-packaging-0@2x.png?format=webp&width=950&nearlossless=1&compression=4'" thus, the element is not being rendered.

I also tried putting the require inside a method:

getImg () { return require(`@/assets/images/box-packaging-0@2x.png?format=${this.webPFormat('png')}&width=950&nearlossless=1&compression=4`); }

And the compiled HTML img element gets like src=(unknown)

And yes, the function webPFormat('png') it is working and returning the expected value (String).

As a side note, even if I hardcode the image source like:

<img src="@/assets/images/box-packaging-0@2x.png?whatever=myparams&are=theyare&being=ignored">

And the compiled HTML would be just <img src="/images/box-packaging-0@2x.**VueHash**.png"> without the params.

Does anyone have any idea how to workaround this issue? 😭

Thank you very much for taking the time to read 👍 ✨


PS: If you're wondering why the params in the image, is because we are now using a CDN to serve static files and images that we can resize and manipulate upon request, so we added to our webpack config:

publicPath: process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'test' ? process.env.VUE_APP_CDN_URL + '/' : '/',

So the assets in production are being served as https://cdn.com/images/image.png instead of https://myvueappsite.com/images/image.png.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda