Front-end axios
this.$axios({
method:"post",
url:"/api/login",
data : { //json
name : this.name,
password: this.password
}
koa
const Koa = require("koa");
const app = new Koa();
const bodyParser = require("koa-bodyparser");
const router = require("./router/main")
app.use(bodyParser()) //POST
app.use(router.routes());
app.use(router.allowedMethods()) //
app.listen(3000);
user.post("/login",async(ctx)=>{
console.log("req.body = "+JSON.stringify(ctx.request.body))
// {"name":"hqb","password":"123"}
console.log("req.body = "+ctx.request.body)
//[object Object]
ctx.body = "LOGIN OK"