- 首先环境需要准备命令如下
npm i jade ,npm i ejs,npm i fs
jade
的语法相对于ejs
更有侵入性,破坏性这里写一个简单的列子来比较分析
html
head
body
div(class=['active','wrapper']) hello this is jade
经过编译后是
<html>
<head></head>
<body>
<div class="active wrapper">hello this is jade</div>
</body>
</html>
这里使用的语法是属性可以写在()里面,包裹的值空一格就可以书写了
ejs书写格式:
<html>
<head></head>
<body>
<div class="active wrapper">hello this is jade</div>
</body>
</html>
大家可以看到ejs没有啥改变。。
- jade中属性中特殊的部分一个是
style
它可以直接使json
数据格式,还有一个是class
它可以直接使用数组格式,但也可以使用普通的格式,如果想要都是json
数据格式,可以用以下格式引用div&attributes({bacgroundColor:'red'})
; ejs
和jade
在语法格式另一个不同在于
html
head
body
div(class=['active','wrapper'],style={height:'100px'}) #{name}
div&attributes({
backgroundColor:'red'
})
-for(let i=0;i<arry.length;i++)
div=arry[i]
<html>
<head></head>
<body>
<div class="active wrapper">hello this is jade</div>
<%for(let i=0;i<3;i++)%{>
<%include a.txt%>
<%}%>
</body>