import axios from 'axios'
axios.all([接口名1,接口名2])
.then(axios.spread((響應1,響應2)=>{
}))
代碼
import { getBanner, getIndexGoods } from "../util/axios";
//單獨調用axios
import axios from "axios";
//調用輕提示
import { Toast } from "vant";
data() {
return {
bannerList: [],
newsList: [],
hotsList: [],
goodsList: []
};
},
mounted() {
//組件加載獲取輪播圖接口
//組件加載獲取商品信息
//並發處理
axios.all([getBanner(), getIndexGoods()]).then(
axios.spread((bannerList, indexGoods) => {
console.log(bannerList, "響應1");
console.log(indexGoods, "響應2");
if (bannerList.code == 200) {
this.bannerList = bannerList.list;
// Toast.success(bannerList.msg);
} else {
Toast.fail(bannerList.msg);
}
if (indexGoods.code == 200) {
this.newsList = indexGoods.list[0].content;
this.hotsList = indexGoods.list[1].content;
this.goodsList = indexGoods.list[2].content;
} else {
Toast.fail(indexGoods.msg);
}
})
);
},