【问题标题】:jade doesn't let me use include #{variable} in a mixin玉不允许我在 mixin 中使用 include #{variable}
【发布时间】:2018-08-13 14:40:08
【问题描述】:

我想打印一个作为 mixin 的结果的包含,但玉想在第一次读取 mixin 时解析包含。

mixin myHeader(name)
  div#{name} 
    h1 #{name}
      include #{name}


!!! html
  html
    head
    body
      +myHeader(#home)
      +myHeader(#schedule)
      +myHeader(#map)
      +myHeader(#lecturers)

我认为错误是告诉我,jade 找不到要包含在 mixin 中的 #{name}。

ENOENT,没有这样的文件或目录 '#{name}.jade'

【问题讨论】:

    标签: pug


    【解决方案1】:

    Jade 不支持包含变量。此stackoverflow question

    中演示了一种解决方法

    【讨论】:

      【解决方案2】:

      也许您可以改用在不同文件中制作的 mixins

      喜欢

      // popups.pug
      mixin temperature()
        h3 temperature
      

      包含在另一个文件中对我来说很好用

      //modal-content.pug
      include popups
      mixin modal-content-popup(component)
      
        .modal-content
          .modal-content__settings
            +#{component}()
          .modal-content__buttons
            button.modal-content__button.modal-content__button--apply Применить
            button.modal-content__button.modal-content__button--close Закрыть
      
      +modal-content-popup('temperature')
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-10-11
        • 1970-01-01
        • 2021-10-17
        • 2014-09-29
        • 1970-01-01
        • 2013-02-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多