http请求顺序执行
串行请求
// 增加async属性
async openPlaybackUrl () {
// 实现:getSucc返回数据后;继续下一步执行
var res = await this.getSucc()
if (res) {
}
}
并行请求
当所有的请求都完成后,会收到一个数组,包含着响应对象,其中的顺序和请求发送的顺序相同,可以使用 axios.spread 分割成多个单独的响应对象
axios.all([
axios.get('https://api.github.com/xxx/1'),
axios.get('https://api.github.com/xxx/2')
])
.then(axios.spread(function (userResp, reposResp) {
// 上面两个请求按顺序都完成后,才执行这个回调方法
console.log('User', userResp.data);
console.log('Repositories', reposResp.data);
}));