执行多个请求 Axios (Vue.js) [英] Performing multiple requests Axios (Vue.js)

查看:44
本文介绍了执行多个请求 Axios (Vue.js)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行两个非并发请求,但想在执行第二个请求之前使用我的第一个请求中的数据.如何实现从第一个请求中获取数据,然后将该数据用于第二个请求?

I am trying to perform two, non-concurrent request, but would like to use data from my first request before performing a second request. How can I achieve getting the data from the first request then using that data for the second request?

axios.get('/user/12345').then(response => this.arrayOne = response.data);
axios.get('/user/12345/' + this.arrayOne.name + '/permissions').then(response => this.arrayTwo = response.data);

推荐答案

您可以将第二个 axios 调用嵌套在第一个调用中.

You can just nest the second axios call inside the first one.

axios.get('/user/12345').then(response => {
   this.arrayOne = response.data
   axios.get('/user/12345/' + this.arrayOne.name + '/permissions').then(
       response => this.arrayTwo = response.data
     );
  });

这篇关于执行多个请求 Axios (Vue.js)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆