1、this.response
{
"url": "http://127.0.0.1:7001/api/user/list",
"ok": true,
"status": 200,
"statusText": "OK",
"headers": {
"map": {
"content-length": ["101"],
"content-type": ["application/json; charset=utf-8"]
}
},
"body": {
"msg": "ok",
"data": [{
"id": "1",
"name": "zhangsan",
"sex": "male"
}, {
"id": "2",
"name": "lisi",
"sex": "male"
}]
},
"bodyText": "{\"msg\":\"ok\",\"data\":[{\"id\":\"1\",\"name\":\"zhangsan\",\"sex\":\"male\"},{\"id\":\"2\",\"name\":\"lisi\",\"sex\":\"male\"}]}"
}
2、this.response.data
{
"msg": "ok",
"data": [{
"id": "1",
"name": "zhangsan",
"sex": "male"
}, {
"id": "2",
"name": "lisi",
"sex": "male"
}]
}
3、this.response.body
{
"msg": "ok",
"data": [{
"id": "1",
"name": "zhangsan",
"sex": "male"
}, {
"id": "2",
"name": "lisi",
"sex": "male"
}]
}
4、this.response.body.data
[{
"id": "1",
"name": "zhangsan",
"sex": "male"
}, {
"id": "2",
"name": "lisi",
"sex": "male"
}]
5、注意事项,后台返回的数据格式如下
async list() {
var userList = [{'id':'1', 'name':'zhangsan', 'sex':'male'},{'id':'2', 'name':'lisi', 'sex':'male'}];
this.ctx.body = {
msg: 'ok',
data: userList
}
}