const koa=require('koa')
const app=new koa()
const ejs = require('ejs')
app.use(async (ctx)=>{
ejs.renderFile('./index.html', {title:'ejs'}, function(err, str){
// str => 输出绘制后的 HTML 字符串
if(err){
ctx.body=err
return
}
ctx.body=str
});
})
app.listen(3004,()=>{
console.log('done')
})
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div><%= title %></div>
<div id='d'>点击</div>
</body>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
console.log(3333)
window.onload = function () {
console.log('eee')
document.querySelector('#d').onclick = function () {
axios.get('http://localhost:3003', {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
}
}
</script>
</html>