nuxt写路由接口

//在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
原文地址:https://www.cnblogs.com/lanshu123/p/10714518.html