我目前正在构建一个需要提交多个POST请求的应用。我想用它axios.all来实现这一点,因为在继续之前,我可以验证每个请求是否成功。
该应用使用axios实例,声明为client。但是,我遇到两个问题:
client没有访问.all迭代方法的权限client.post数组添加请求会立即执行它们这是我正在使用的代码的示例:
import axios from 'axios'
const client = axios.create({
baseURL: process.env.API_URL
})
let requests = []
for (let section of {{ some data }}) {
requests.push(client.post('response_endpoint', section.responses))
}
client.all(requests)
Run Code Online (Sandbox Code Playgroud)
有什么方法可以使这项工作奏效,还是需要重新考虑我的方法?