2017-06-19 28 views
1

我在我的jade文件中使用了mixin。要求是有两个div。如果我只创建一个DIV它呈现,但如果我用两个混入渲染我得到错误的内容:“未定义jade_mixins.selectedImage卡是不是一个函数”JADE/PUG:无法使用两个mixin

这里是玉代码:

.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) 
+0

你应该把混入代码的缩进之外,这样的事情: –

回答

0

错误是您的缩进。把你的代码在编译器会导致以下错误:

> 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 

提供额外的前导空格,声明混入后,它会工作。

理想情况下,您应该在文件的开头定义mixins,并在建议的in comments后面的阶段引用它们。

0

将mixin代码放在​​缩进外。

例子:

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)