在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)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...