Nextjs:无法从静态文件夹加载图像 [英] Nextjs: Unable to load images from static folder
问题描述
如何在Next.js的组件中加载图像?我必须先构建项目吗?如果是,是否有一种无需先构建就可以加载图像的方法?无论我如何尝试,我都无法正常工作.
How can I load images in a component in Next.js? Do I have to build the project first? If yes, is there a way to load the images without building first? I cannot get this to work, no matter what I try.
推荐答案
只需将文件放置在static
目录中,即可在应用中引用它们,例如:
Just place your files in static
directory then you can reference them in your app like:
<img src="/static/my-image.png" />
我认为next.js将在此目录中进行监视,因此我认为您每次在其中放置内容时都不需要重新start
服务器.
I think next.js will have a watch on this directory so I don't think you need to restart
your server every time you put something in there.
但是,当然,您的生产版本将在什么时候更新.每次在应用程序中进行更改时,都需要build
.
But of course when your production build will get updated. You need to build
it every time you change something in your app.
这篇关于Nextjs:无法从静态文件夹加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!