2017-06-19 31 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)