0
点赞
收藏
分享

微信扫一扫

Koa(八):Cookie


示例

const Koa = require('koa'),
router = require('koa-router')();

const app = new Koa();

router
.get('/', async ctx => {

let data = ctx.cookies.get('name');

ctx.body = `<h1>${data}</h1>`;

})
.get('/login', async ctx => {

ctx.cookies.set('name', 'ProsperLee', { maxAge: 3000 });

ctx.body = '<a href="/">index</a>';

})

app
.use(router.routes())
.use(router.allowedMethods())
.listen(3000);

console.log('Server run in http://localhost:3000/');

结果

Koa(八):Cookie_nodejs


举报

相关推荐

0 条评论