生于理想

导航

2022年9月23日 #

app.locals

摘要: 将变量设置到app.locals对象下面,这个数据在所有的模板中都可以获取到。 app.locals.users = [{ name: 'zhangsan', age: 20 },{ name: '李四', age: 30 }] 在模板中循环遍历 <ul> {{each users}} <li> { 阅读全文

posted @ 2022-09-23 17:36 生于理想 阅读(60) 评论(0) 推荐(0)

模板配置-模板根目录及后缀配置

摘要: const template = require('art-template'); const path = require('path'); // 时间 const sd = require('silly-datetime'); //设置模板根目录 template.defaults.root = 阅读全文

posted @ 2022-09-23 17:17 生于理想 阅读(30) 评论(0) 推荐(0)

Express路由参数

摘要: // 引入express框架 const express = require('express'); const bodyParser = require('body-parser'); // 创建网站服务器 const app = express(); app.get('/index/:id/:n 阅读全文

posted @ 2022-09-23 17:09 生于理想 阅读(26) 评论(0) 推荐(0)

Express中GET,POST参数获取

摘要: GET Express框架中使用req.query即可获取GET参数,框架内部会将GET参数转换为对象并返回。 // 引入express框架 const express = require('express'); // 创建网站服务器 const app = express(); app.get(' 阅读全文

posted @ 2022-09-23 17:08 生于理想 阅读(87) 评论(0) 推荐(0)

express框架中配置模板引擎

摘要: npm安装 npm install art-template express-art-template 使用 const express = require('express'); const path = require('path'); const app = express(); // 1.告 阅读全文

posted @ 2022-09-23 17:04 生于理想 阅读(73) 评论(0) 推荐(0)