2017-03-11 37 views
0

同一 .jade文件我有:node.js中的Javascript与浏览器(Chrome)有所不同吗?

script. 
    if (user) 
    ...//using jQuery to change color theme 

也:

li 
-if (user) 
    a(href='/lougout') 
-else 
    a(href='/login') 

如果user不存在,在Chrome以下错误的结果:

Uncaught ReferenceError: user is not defined

第二个工作没有任何问题,即node.js服务器/ Jade引擎不支持在。

这是怎么发生的?

回答

0

script之后的.表示其内容是文字。 if (user)排放到<script>,没有评估:

<script> 
if (user) 
    ... // using jQuery to change color theme 
</script> 
+0

我已经更新了我的问题,以使其更清晰,首先是在浏览器中执行,第二个是在服务器中。 –

+0

@OldGeezer:所以'用户'没有在浏览器中定义... – Ryan

+0

谢谢,我现在明白了。我的问题是使用不正确的插图。我想问的是,如果(someobject)...不会在Jade或node.js中导致错误,即使未声明someobject也是如此。 –

相关问题