vue中的并发处理

axios的并发处理
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);
      }
    })
  );
},
 

六、分类页面

上一篇:VSS迁移备忘


下一篇:[vue] 暴露组件为一个Vue实例(用于在js调用组件。类似this.$toast