Nextjs:无法从静态文件夹加载图像 [英] Nextjs: Unable to load images from static folder

查看:1347
本文介绍了Nextjs:无法从静态文件夹加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆