admin管理员组文章数量:1406943
The question is that I am having 10 images in my public
folder and I want to use them in a ponent. Instead of writing
import imgurl1 from "../../public/celsius.gif";
import imgurl2 from "../../public/pass.gif";
import imgurl3 from "../../public/rain.gif";
.
.
.
import imgurl8 from "../../public/thermo.gif";
import imgurl9 from "../../public/sunset.gif";
import imgurl10 from "../../public/wind.gif";
the above code, I want to use something more neatly and clean code? Is there any way not to repeat the same line and import all of them?
I am assuming something like
import { imgurl1,imgurl2,...imgurl10, } from "../../public";
The question is that I am having 10 images in my public
folder and I want to use them in a ponent. Instead of writing
import imgurl1 from "../../public/celsius.gif";
import imgurl2 from "../../public/pass.gif";
import imgurl3 from "../../public/rain.gif";
.
.
.
import imgurl8 from "../../public/thermo.gif";
import imgurl9 from "../../public/sunset.gif";
import imgurl10 from "../../public/wind.gif";
the above code, I want to use something more neatly and clean code? Is there any way not to repeat the same line and import all of them?
I am assuming something like
import { imgurl1,imgurl2,...imgurl10, } from "../../public";
Share
Improve this question
asked Mar 28, 2022 at 14:59
MagnusEffectMagnusEffect
3,9353 gold badges27 silver badges61 bronze badges
1 Answer
Reset to default 6Next JS's importing of images is implemented as a webpack plugin which is implemented using import symbol from 'filepath
- You won't be able to change the way that works directly, but there is nothing preventing you from creating a helper file that exports the imported files.
In other words, you can take all your imports and move them to images.js
and export all of them at the bottom. You then can import them using a destructured import.
本文标签: javascriptHow to import multiple Images neatly in nextjsStack Overflow
版权声明:本文标题:javascript - How to import multiple Images neatly in nextjs? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744667981a2618649.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论