我正在尝试执行两个非并发请求,但想在执行第二个请求之前使用第一个请求中的数据。如何实现从第一个请求获取数据然后将该数据用于第二个请求?
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
调用嵌套在第一个调用中。
axios.get('/user/12345').then(response => {
this.arrayOne = response.data
axios.get('/user/12345/' + this.arrayOne.name + '/permissions').then(
response => this.arrayTwo = response.data
);
});
关于http - 执行多个请求 Axios (Vue.js),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41787994/