Analysis of koa2 routing

Insert picture description here
We can't directly return a value in koa, so the front-end can't get this value

We need to mount the value (mostly json in actual development) ctx.body, so that the front end can get the data.
If we return an object, koa will automatically convert this object into a json object and add it to the Response HeadersContent-Type: application/json
Insert picture description here
Insert picture description here

koa-router

The use of koa-router can be divided into these three steps:
Insert picture description here

Guess you like

Origin blog.csdn.net/dyw3390199/article/details/114085723