Skip to content Skip to sidebar Skip to footer

Why Image Path Is Not Resolved By Require() When Passed As Prop In NuxtJS?

In my NuxtJS project I have a component that recieves an image path as a prop. I tried passing it directly to :src='imageAddress' but it neither resolve nor throws an error. Then I

Solution 1:

You can try to make method in ChildComponent:

getUrl (img)  {
  return require(`~/assets/icons/${img}.png`);
}

then in template:

<img :src="getUrl(imageAddress)" alt="" />

Post a Comment for "Why Image Path Is Not Resolved By Require() When Passed As Prop In NuxtJS?"