zoukankan      html  css  js  c++  java
  • nodejs 模板引擎jade的使用

    1、test.jade文件

    html
        head
            style
        body
            div.box
                div#div1
            div aaa
            div(class="aaa left-warp active")
    
            div(style="200px;height:200px;background:red")
            div(style= { '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端口即可展示页面

  • 相关阅读:
    微微一笑很倾城(1)
    微微一笑很倾城(1)
    陈先生与程太太
    陈先生与程太太
    我在这
    我在这
    曾有一个人,爱我如生命(2)
    曾有一个人,爱我如生命(2)
    周末情妇
    [转载]黄泉嫁衣
  • 原文地址:https://www.cnblogs.com/gopark/p/9779572.html
Copyright © 2011-2022 走看看