下面有什么区别吗?
controllers
async function get (ctx, next) {
const res = await models.test.get()
ctx.state.data = res.data
/******* 或者 ********/
ctx.body = res.data
await next()
}
module.exports = {
get
}
routes
router.get('/', controllers.test.get, async (ctx, next) => {
await ctx.render('test', {
list: ctx.state.data.obj,
/******* 或者 ********/
list: ctx.body.obj,
})
})
state是用来给中间件保存数据的,而body是最终的输出