简体   繁体   English

JADE / PUG:无法使用两个mixins

[英]JADE/PUG: Unable to use two mixins

I am using mixin in my jade file. 我在我的玉文件中使用mixin。 The requirement is to have two divs. 要求是有两个div。 If I create only a single div it renders but if I use two mixins to render the content I get error: "undefined jade_mixins.selectedImage-card is not a function" 如果我只创建一个div它渲染,但如果我使用两个mixin来呈现内容我得到错误:“undefined jade_mixins.selectedImage-card不是一个函数”

Here is the jade code: 这是玉代码:

.container
        .allThumbs
          h2 All 
          .row
           mixin allImage-card(photo)
            .col-lg-4.col-md-4.col-sm-4.col-xs-6
              .imgThumb
                img.thumb(src=photo.URL, alt="")

        for photo in _allPhotos
          +allImage-card(photo)

        .allThumbs
          h2 Selected
          .row
            mixin selectedImage-card(photo)
            .col-lg-4.col-md-4.col-sm-4.col-xs-6
              .imgThumb
                img.thumb(src=photo.URL, alt="")

        for photo in _selected
          +selectedImage-card(photo)

The error is your indentation. 错误是你的缩进。 Putting your code in a compiler results in the following error: 将代码放入编译器会导致以下错误:

  > 24|             mixin selectedImage-card(photo)
--------------------^
    25|             .col-lg-4.col-md-4.col-sm-4.col-xs-6
    26|               .imgThumb
    27|                 img.thumb(src=photo.URL, alt="")

Mixin selectedImage-card declared without body

Give an additional leading space, after declaring the mixin, and it will work. 在声明mixin之后给出一个额外的领先空间,它会起作用。

Ideally, you should define mixins at the beginning of the file, and refer them at a later stage as suggested in comments . 理想情况下,您应该在文件的开头定义mixins,并在评论中建议的稍后阶段引用它们。

Put the mixin code outside the indentation. 将mixin代码放在​​缩进之外。

Example: 例:

mixin allImage-card(photo)
   .example 
      !{photo.name}

mixin selectedImage-card(photo)
   .test 
      !{photo.name}


.container
    -var _allPhotos = [{'name':'john'}, {'name': 'fred'}]
    -var _selected = [{'name':'luka'}, {'name': 'lisa'}]

    for photo in _allPhotos
      +allImage-card(photo)

    .allThumbs
      h2 Selected
      .row
    for photo in _selected
      +selectedImage-card(photo)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM