axios 并发请求

参考资料 https://www.jianshu.com/p/960571352bef

参考资料 https://www.jianshu.com/p/f369358803fd

 

 同时进行多个请求,并统一处理返回值;

两步:

1,axios.all([]).then()

2,axios.spread()

  methods: {
    getAllTask() {
      return axios.get('/data.json', {
        params: {
          id: 10
        }
      })
    },
    getAllCity() {
      return axios.get('/city.json', {
        params: {
          id: 11
        }
      })
    }
  },
  mounted() {
    axios.all([this.getAllTask(), this.getAllCity()])
      .then(axios.spread(function(allTask, allCity) {
        console.log('请求1结果', allTask)
        console.log('请求2结果', allCity)
      }))
  },

 

posted @ 2020-08-10 17:03  秋风2016  阅读(102)  评论(0编辑  收藏  举报