深海里的小虾米
2019-01-11 10:17使用koa时接口中有异步操作时返回数据问题
var fn_index = async (ctx, next) => {
let login = () => {
return new Promise((res, req) => {
setTimeout(()=>{
res(‘异步’)
},5000)
})
}
let res = await login()
console.log(res)
ctx.response.body = { mag: '账号或密码错误' }
}
module.exports = {
'/api/login': {
type: 'POST',
method: fn_index
}
}
```这个时候接口接收到的返回信息是404 notfond
去掉setTimeout的时候就是正常的
想要异步返回需要如何操作
- 点赞
- 回答
- 收藏
- 复制链接分享
0条回答
为你推荐
- vue获取不到淘宝城市api的数据
- vue.js
- ecmascript
- node.js
- 2个回答