【问题标题】:Jade/Pug: variable not showing in mixinJade/Pug:变量未在 mixin 中显示
【发布时间】:2016-07-07 19:34:42
【问题描述】:

我是 Jade/Pug 的新手,当我没有将带有变量的代码放入 mixin 时,它可以正常工作,但是当我使用 mixin 时,变量没有任何显示。我希望有人能解释我如何在变量中正确使用 mixins。

//-works
.teacher-wrapper
  .teacher-container
    each student in students
      .studentCardContainer.shadow90
        .studentInfoContainer
          .studentPhotoContainer
            .studentPhoto
              img(src="some_img.jpg")
            .studentName= student //<------ works
        .studentEmotionContainer
          div text
          div text

在此示例中,我想为每个学生使用一个 mixin,但 = student 不起作用。我也试过#{student},但没用。

//- doesn't work
 .teacher-container
    each student in students
      +studentCard

    mixin studentCard
      .studentCardContainer.shadow90
        .studentInfoContainer
          .studentPhotoContainer
            .studentPhoto
              img(src="some_img.jpg")
            .studentName= student//<------ doesn't work ?
        .studentEmotionContainer
          div text
          div text

【问题讨论】:

    标签: express pug


    【解决方案1】:

    您需要将 student 设置为您的 mixin 的参数:

    mixin studentCard(student)
      .studentCardContainer.shadow90
        .studentInfoContainer
          .studentPhotoContainer
            .studentPhoto
              img(src="some_img.jpg")
            .studentName= student
        .studentEmotionContainer
          div text
          div text
    
    .teacher-container
      each student in students
        +studentCard(student)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-29
      • 1970-01-01
      • 1970-01-01
      • 2016-09-23
      • 1970-01-01
      • 2017-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多