使用場景:多個請求方法拿到數據之后需要對這不同的數據進行比較,之后在輸出並渲染
思路:使用promise.all()異步操作:
Promise.all([ //上架 new Promise((resolve,reject)=>{ this.axios(config.API + '/api/aply/statistics/hit_the_shelf',{},params).then((res)=>{ console.log(res) resolve(res) }) }), //上架環比 new Promise((resolve,reject)=>{ this.axios(config.API + '/api/aply/statistics/hit_the_shelf',{},params1).then((res)=>{ conso.log(res1) resolve(res1) }) }), ]).then(res=> { console.log(res) //是一個數組,里邊的res[index]值就是兩個不同的請求返回的結果 })