基础
获取参数
在 Controller 中通过 ctx 获取;三种方式:
ctx.query:/user?id=idctx.params:/user/:idctx.request.body:/user表单或 JSON 提交,在请求体中
js
class HomeController extends Controller {
async index() {
const { ctx } = this;
const { id } = ctx.query;
ctx.body = id;
}
async userId() {
const { ctx } = this;
const { id } = ctx.params;
ctx.body = id;
}
async post() {
const { ctx } = this;
const { name } = ctx.request.body;
ctx.body = {
name,
};
}
}
前端小册