Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Vue "Module not found" error after switching image url to and online image

I’m trying to dynamically display images, whose names I fetch as strings from a backend. I’m storing all my images in my assets folder, but since there are many images I want to store them online, but keep the same logic for displaying them. The way I did it until now is:

  methods: {
    getImage(image) {
      return require(`@/assets/${image}`);
    }
  }

and in HTML:

<img class="moduleImage" :src="getImage(module.pictureName)" :alt="module.name">

Now I try the following in the getImage(image) method:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

getImage(image) {
  return require(`https://onlineImageStorage.com/${image}`);
}

and I get a Module Not Found error.

>Solution :

Remove the "require" keyword since it’s not anymore in your sources :

getImage(image) {
  return `https://onlineImageStorage.com/${image}`;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading