koa-mysql(二)
路由
安装依赖
cnpm install koa-router --save
修改index.js
const koa = require('koa'); const router = require('koa-router')(); const app = new koa(); router.get('/',async(ctx,next) => { ctx.response.body = "<h1>hello,world</h1>" }) app.use(router.routes()); app.listen(3000); console.log(`app start at localhost:3000`);
http://localhost:3000/
别的页面
const koa = require('koa'); const router = require('koa-router')(); const app = new koa(); router.get('/',async(ctx,next) => { ctx.response.body = "<h1>hello,world</h1>" }) router.get('/hello',async(ctx,next) => { ctx.response.body = "this is hello page" }) router.get('/hello/:name',async(ctx,next) => { var name = ctx.params.name; ctx.response.body = `<h1>hello,${name}</h1>` }) app.use(router.routes()); app.listen(3000); console.log(`app start at localhost:3000`);
http://localhost:3000/hello
http://localhost:3000/hello/biao
post
相关推荐
liwf 2020-11-10
sjun0 2020-11-12
做对一件事很重要 2020-09-07
BraveWangDev 2020-08-19
songshijiazuaa 2020-08-15
FanErZong 2020-07-18
大慧 2020-07-04
houjinkai 2020-06-18
LUOPING0 2020-06-16
Carlos 2020-06-16
85427617 2020-06-13
心丨悦 2020-06-13
guicaizhou 2020-06-12
wenjieyatou 2020-06-08
stoneechogx 2020-06-04
minggehenhao 2020-06-02
msmysql 2020-06-02