node+koa2 向頁面傳值方式

1.async

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

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

2.orm

ctx.response.body='ok'router

3.get

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!'
})it

相關文章
相關標籤/搜索