nuxt写路由接口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//在server/interface/city.js
import Router from 'koa-router';
const router = new Router({
prefix:'/city' //给路由添加前缀
})
router.get('/list', async (ctx) => {
ctx.body=['北京','天津']
})
export default router;


//在server/index.js
import cityInterface from './interface/city'
app.use(cityInterface.routes()).use(cityInterface.allowedMethods()) //固定写法

测试一下curl http://localhost:3000/city/list 或者浏览器输入http://localhost:3000/city/list

#

评论

Your browser is out-of-date!

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

×