- export default {
- data () {
- return {
- ids: [561, 562, 563, 564]
- }
- },
-
- methods: {
- createRecord (id) {
- return axios.post('/business/record', { id }).then((response) => {
- return response.data
- })
- }
- },
-
- mounted () {
-
- // 创建一个包含异步任务的数组,每个任务都是一个 axios 请求
- const arrays = []
- this.ids.forEach(id => {
- arrays.push(this.createRecord(id))
- })
-
- // 当所有请求都成功完成时,responses 是一个包含所有响应的数组
- Promise.all(arrays).then(responses => {
- console.log(responses)
- }).catch(error => {
- // 如果任何一个请求失败,将会进入这个 catch 块
- console.log(error)
- })
-
- }
- }
- [
- {
- "code": 200,
- "msg": "新增成功"
- },
- {
- "code": 200,
- "msg": "新增成功"
- },
- {
- "code": 200,
- "msg": "新增成功"
- },
- {
- "code": 200,
- "msg": "新增成功"
- }
- ]