我有一张图片,我想将其显示为主页的背景。这就是我正在做的,
background: url(../../imgs/b2.jpeg) no-repeat center fixed;
图像位于“imgs”文件夹中,导航正确。现在,我正在监听本地主机地址的端口 5000
。 (127.0.0.1)
当我预览我的应用程序时,图像由于以下错误而无法加载,
http://127.0.0.1:3000/imgs/b1.jpeg - Failed to load resource: the server responded with a status of 404 (Not Found)
这是因为浏览器正在查找与 IP 地址相关的文件。在这种情况下,我如何在本地保存的图像中指定正确的位置?
谢谢!
最佳答案
这就是我最终解决它的方法,我设置了我的应用程序来为公共(public)目录提供服务,
app.use(express.static(__dirname + "/public"));
之后,这就是我指定存储在 public/imgs
中的图像路径的方式
localhost:3000/imgs/b1.jpeg
瞧,它成功了!
关于html - Node.js( express ): How to include correct value for 'src' attribute of an 'img' tag?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38731066/