我是JS和Vue的新手。
我有100行发送到后端的网址。我使用了for循环来调用api,并且每一行都是数据。
<template>
<table>
<thead>
<tr>
<th>No.</th>
<th>Url</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr v-for="(post, index) in posts">
<td>{{ index + 1}}</td>
<td>{{ post.url}}</td>
<td class="classStatus(post.status)">{{ post.status}}</td>
</tr>
</tbody>
</table>
脚本:
const apiUrl = 'example.com/api/createPost'
for (post of this.posts) {
// Sent only posts with status READY or FAIL
if (post.status === STATUS_SUCCESS) {
continue;
}
// Call api to process post one by one
this.apiService(apiUrl, post)
.then(result => {
post.status = STATUS_SUCCESS
}).catch(err => {
post.status = STATUS_FAIL
})
}
它适用于案例单发(api调用1次):
但是,如果有多个帖子:
您能帮我知道为什么发生了多个帖子吗?