Jade 在本地机器上导致错误,但在演示网站上没有
Jade causing error on local machine but not on demo website
我运行这个
mixin eventpics(pics)
.eventpics
each p in pics
.col-xs-4
img.img-responsive(src=p)
- var event_pics = ['a', 'b']
+eventpics(event_pics)
在 jade demo page 上它工作得很好,但是当我尝试使用 jade 命令行工具输出 html 我得到这个错误
TypeError: jade/myfile.jade:12
10| mixin eventpics(pics)
11| .eventpics
> 12| each p in pics
13| .col-xs-4
14| img.img-responsive(src=p)
15|
Cannot read property 'length' of undefined
at Object.eval (eval at <anonymous> (/usr/local/lib/node_modules/jade/lib/index.js:190:8), <anonymous>:20:31)
at Object.jade_mixins.eventpics (eval at <anonymous> (/usr/local/lib/node_modules/jade/lib/index.js:190:8), <anonymous>:57:4)
at eval (eval at <anonymous> (/usr/local/lib/node_modules/jade/lib/index.js:190:8), <anonymous>:666:25)
at eval (eval at <anonymous> (/usr/local/lib/node_modules/jade/lib/index.js:190:8), <anonymous>:1937:22)
at res (/usr/local/lib/node_modules/jade/lib/index.js:191:38)
at /usr/local/lib/node_modules/jade/bin/jade.js:190:48
at /usr/local/lib/node_modules/jade/node_modules/mkdirp/index.js:47:26
at Object.oncomplete (fs.js:107:15)
所以我想通了这个问题。我没有在示例中包含我的所有代码,事实证明我应该包含。我正在扩展一个 layout.jade 文件,并且我已经在扩展它的文件中定义了所有 - var foo = bar
。这使得它们在 layout.jade 文件中未定义,除非我在 layout.jade 中定义了一个块 block vars
,然后将该块中的变量放入扩展它的文件中。
解决方案如下所示:
layout.jade
block vars
block content
extending.jade
extends layout
mixin eventpics(pics)
.eventpics
each p in pics
.col-xs-4
img.img-responsive(src=p)
block vars
- var event_pics = ['a', 'b']
block content
+eventpics(event_pics)
我运行这个
mixin eventpics(pics)
.eventpics
each p in pics
.col-xs-4
img.img-responsive(src=p)
- var event_pics = ['a', 'b']
+eventpics(event_pics)
在 jade demo page 上它工作得很好,但是当我尝试使用 jade 命令行工具输出 html 我得到这个错误
TypeError: jade/myfile.jade:12
10| mixin eventpics(pics)
11| .eventpics
> 12| each p in pics
13| .col-xs-4
14| img.img-responsive(src=p)
15|
Cannot read property 'length' of undefined
at Object.eval (eval at <anonymous> (/usr/local/lib/node_modules/jade/lib/index.js:190:8), <anonymous>:20:31)
at Object.jade_mixins.eventpics (eval at <anonymous> (/usr/local/lib/node_modules/jade/lib/index.js:190:8), <anonymous>:57:4)
at eval (eval at <anonymous> (/usr/local/lib/node_modules/jade/lib/index.js:190:8), <anonymous>:666:25)
at eval (eval at <anonymous> (/usr/local/lib/node_modules/jade/lib/index.js:190:8), <anonymous>:1937:22)
at res (/usr/local/lib/node_modules/jade/lib/index.js:191:38)
at /usr/local/lib/node_modules/jade/bin/jade.js:190:48
at /usr/local/lib/node_modules/jade/node_modules/mkdirp/index.js:47:26
at Object.oncomplete (fs.js:107:15)
所以我想通了这个问题。我没有在示例中包含我的所有代码,事实证明我应该包含。我正在扩展一个 layout.jade 文件,并且我已经在扩展它的文件中定义了所有 - var foo = bar
。这使得它们在 layout.jade 文件中未定义,除非我在 layout.jade 中定义了一个块 block vars
,然后将该块中的变量放入扩展它的文件中。
解决方案如下所示:
layout.jade
block vars
block content
extending.jade
extends layout
mixin eventpics(pics)
.eventpics
each p in pics
.col-xs-4
img.img-responsive(src=p)
block vars
- var event_pics = ['a', 'b']
block content
+eventpics(event_pics)