javascript - 在 Pug/Jade 模板引擎中显示图像
问题描述
我正在尝试显示来自对象的图像以获取 Http 方法('/campgrounds')。使用 campgrounds 数组获取 Http 方法有 3 个具有 2 个属性的对象 如何在主页中显示图像链接?
app.set("view engine", "pug");
app.get('/campgrounds', (req, res) => {
const campgrounds = [
{
Name: "Name1",
Image: "https://images.unsplash.com/photo-1571687949921-1306bfb24b72?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60"
},
];
res.render("campgrounds", { campgrounds: campgrounds });
});
这是campgrounds.pug页面
html
head
body
h1 This is the Campgrounds Page!
each val in campgrounds
ul
li=val.Name
li=img(src=val.Image) // get the images as stirng links
解决方案
缩进img
标签:
each val in campgrounds
ul
li=val.Name
li
img(src=val.Image)
推荐阅读
- windows - 作为本地系统的服务很好,但作为网络服务的模块有故障?
- c++ - C++ - std::vector foreach - 没有重载函数的实例
- elasticsearch - 将 Elasticsearch 快照从 Windows 恢复到 Debian
- python - 使用 CMDS 在 Maya 中获取选定定位器的变换
- c++ - 将字符串中出现的 bigint 除以 2
- c# - RedirectToAction 在生产环境中间歇性挂起
- c# - Outlook点击链接事件?
- python - 用底图绘制小河
- wordpress - Wordpress - 短 mp4 视频而不是特色图片
- python - 如何在 pyspark.bucketizer 中获取拆分值而不是存储桶索引