例子
const Koa = require(‘koa‘); const render =require(‘koa-art-template‘); const path= require(‘path‘); //创建服务器 const app=new Koa(); //渲染 render(app, { root: path.join(__dirname, ‘view‘), extname: ‘.html‘, debug: process.env.NODE_ENV !== ‘production‘ }); app.use(async function (ctx) { await ctx.render(‘index‘); }); app.listen(8888,()=>{ console.log(‘启动了‘) });
效果:
输出: hello world
原文:https://www.cnblogs.com/guangzhou11/p/10176998.html