koa路由接口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const router = require('koa-router')()
//返回一个页面
router.get('/', async (ctx, next) => {
global.console.log('index11111');
await ctx.render('index', { //render返回一个页面
title: 'Hello Koa 2!'
})
})
//直接返回数据的用body,json数据
router.get('/json', async (ctx, next) => {
ctx.body = {
title: 'koa2 json'
}
})
//在不同页面为了区分接口,我们可以在加个前缀/user
router.prefix('/users')
module.exports = router

// app.js文件
app.use(index.routes(), index.allowedMethods())
#

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×