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

232
Views
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
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!