[使用Axios,我正在尝试:
具有成功响应(或有错误,返回错误)的发布请求
如果第一个请求成功,则在响应中使用返回值,然后将第二个请求发布到不同的端点
我最近遇到的是:
import axios from 'axios';
let one = "https://api.storyblok.com/v1/cdn/stories/health?version=published&token=wANpEQEsMYGOwLxwXQ76Ggtt"
let two = "https://api.storyblok.com/v1/cdn/datasources/?token=wANpEQEsMYGOwLxwXQ76Ggtt"
let three = "https://api.storyblok.com/v1/cdn/stories/vue?version=published&token=wANpEQEsMYGOwLxwXQ76Ggtt"
const requestOne = axios.get(one);
const requestTwo = axios.get(two);
const requestThree = axios.get(three);
axios.all([requestOne, requestTwo, requestThree]).then(axios.spread((...responses) => {
const responseOne = responses[0]
const responseTwo = responses[1]
const responesThree = responses[2]
// use/access the results
})).catch(errors => {
// react on errors.
})
但是这会立即调用,因此我无法将值传递给第二个帖子,如果那是有道理的?
所以遇到了这个并尝试:
在您的情况下,这不适用,因为第二个api调用取决于第一个api调用结果。