node+koa2 向页面传值方式

1.

router.post('/form',async(ctx,next)=>{
const form = ctx.request.body;
console.log('用户名:'+form.userName+'----'+'密码:'+form.password);

ctx.body = {
resultCode:200
}
});

2.

ctx.response.body='ok'

3.

var arr = [1,3,4,5,6]
router.get('/',async (ctx, next) => {
//console.log('接受到的参数为:'+ctx.request.query.user);
const body = ctx.request.query;
console.log(body.user+'----'+body.age+'----'+body.body)
console.log('arr类型:'+ Array.isArray(arr))
//ctx.redirect('http://www.baidu.com')
await ctx.render('index', {
title:arr //'Hello Koa 22222222222222222!'
})

posted @ 2018-03-20 14:23  江山一族  阅读(2279)  评论(0编辑  收藏  举报