jeda模板

模板引擎:
主流:jade - 侵入 强依赖
ejs -非侵入 不破坏原有 若依赖

ejs

npm install ejs

语法:

<%= name %>
<%= json.arr[9].name %>
<%= 12+5 %>
<% for(var i = 0;i<arr.length;i++){ %>
   <div><%= arr[i]%><div>
<%}%>
<%- <div></div> %> 输出html模板
<% include a.text %> 引入模板 可以跟循环等嵌套 只能引入路径  
<% if(type == admin){
    <% include ../css/a.css %>
<%}else { %>
    <% include ../css/b.css %>
<% / %>

js:

const ejs = require('ejs')


ejs.renderFile('./www/a.ejs',{'name':'zhangsan'},function (err,data) {
    if(err){
        console.log('fail')
    }else{
        console.log(data)
    }
})

猜你喜欢

转载自blog.csdn.net/aruking/article/details/80110806