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

Time:01-28

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  :src="getImage(module.pictureName)" :alt="module.name">

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

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

and I get a Module Not Found error.

CodePudding user response:

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

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