nodejs 模板引擎jade的使用

1、test.jade文件

html
    head
        style
    body
        div.box
            div#div1
        div aaa
        div(class="aaa left-warp active")

        div(style="width:200px;height:200px;background:red")
        div(style= {width: '200px', height: '200px', background: 'blue'})
        div(title= ['aaa', 'left-warp', 'active'])
        div(title="aaa",id="div2")

2、jade.js文件

var jade=require('jade');
var http = require('http');
var str=jade.renderFile('test.jade',{pretty:true});
//创建服务
http.createServer(function(req,res){
    res.writeHeader(200, {'Content-Type':'text/html;charset:utf-8'});
    res.write('<head><meta charset="utf-8"/></head>');
    res.write(str);
    res.end('<p>渲染结束</p>');
}).listen(8888,"localhost",function () {
    console.log("open server at port:8888...");
});

3、浏览器直接访问8888端口即可展示页面

猜你喜欢

转载自www.cnblogs.com/gopark/p/9779572.html