前端学习nodejs,以前写这种需要两个接口数据的时候,都是请求一个接口,然后在回调函数中再请求下一个接口,然后第二次请求的回调函数中处理数据,这次是用express和vue写一个类似dotamax的东西,用的opendota的接口,在输入id的入口处,我想请求该用户的个人信息(如头像,id,昵称等),同时还想请求该用户在近期的5场比赛,所以就还是先请求players这个接口,然后在回到函数里面请求matches的数据,我总觉得这样不是很好。菜鸟,望大家指教。
认证0级讲师
Not goodCaught in callback hell. Solution:
Promise
async/await
Events
Judging from your code, it is relatively easy to access using events. 1. Listen to the event after the first function is executed [assuming 'request1done'] 2. Trigger the event ['request1done'] in the first function callback
Not good
Caught in callback hell.
Solution:
Promise
async/await
Events
Judging from your code, it is relatively easy to access using events.
1. Listen to the event after the first function is executed [assuming 'request1done']
2. Trigger the event ['request1done'] in the first function callback