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端口即可展示頁面

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM