this.query的query是什么哪来的?
来源:4-3 第四天 自动回复各种消息
蓝with黑
2017-07-18
genator.js 里 console.log(this)
输出的是这个:
{ "request": { "method": "POST", "url": "/?signature=0df9702db39eff72431fbd6d7e2ae5e8d397904b×tamp=1500341060&nonce=876654093&openid=osgZos0gMAn2VqcUJa8YzbE_GO8s", "header": { "user-agent": "Mozilla/4.0", "accept": "*/*", "host": "wxfan.ngrok.cc", "pragma": "no-cache", "content-length": "276", "content-type": "text/xml" } }, "response": { "status": 404, "message": "Not Found", "header": {} }, "app": { "subdomainOffset": 2, "proxy": false, "env": "development" }, "originalUrl": "/?signature=0df9702db39eff72431fbd6d7e2ae5e8d397904b×tamp=1500341060&nonce=876654093&openid=osgZos0gMAn2VqcUJa8YzbE_GO8s", "req": "<original node req>", "res": "<original node res>", "socket": "<original node socket>"
为什么 this.query是这个?前面的this对象里并没有query这个key
this.query: { signature: '0df9702db39eff72431fbd6d7e2ae5e8d397904b', timestamp: '1500341060', nonce: '876654093', openid: 'osgZos0gMAn2VqcUJa8YzbE_GO8s' }
2. 这里 this.charset this.length 也是undefined
console.log('test this charset:',this.charset); console.log('test this length:',this.length); let data=yield getRawBody(this.req,{ length:this.length, limit:'1mb', encoding:this.charset }) // 后台输出: ------------------------------- test this charset: undefined test this length: undefined ------------------------------
写回答
1回答
-
Scott
2017-07-18
你用的 koa 1.x 还是 2.x
如果是 2.x
(ctx, next) {
let query = ctx.query
}
要用 ctx 来拿到 query
00
相似问题