且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么在 NuxtJS 中作为 prop 传递时,require() 没有解析图像路径?

更新时间:2023-11-13 19:42:58

可以尝试在ChildComponent中make方法:

You can try to make method in ChildComponent:

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

然后在模板中:

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