我有一个API可以为留言板线程返回一个回复列表(每次通话限制5个回复)。我正在尝试做的是在响应中寻找特定的答复uuid。如果未找到,请为接下来的5个回复创建另一个AXIOS GET调用。我怎样才能“while循环”一个Axios GET调用,直到满足条件?
我想继续此循环,直到调用UUID或AXIOS GET调用返回而没有结果。
实施例API请求:
http://localhost:8080/api/v2/replies?type=thread&key=e96c7431-a001-4cf2-9998-4e177cde0ec3
实施例的API的回复:
"status": "success",
"data": [
{
"uuid": "0a6bc471-b12e-45fc-bc4b-323914b99cfa",
"body": "This is a test 16.",
"created_at": "2017-07-16T23:44:21+00:00"
},
{
"uuid": "0a2d2061-0642-47eb-a0f2-ca6ce5e2ea03",
"body": "This is a test 15.",
"created_at": "2017-07-16T23:44:16+00:00"
},
{
"uuid": "32eaa855-18b1-487c-b1e7-52965d59196b",
"body": "This is a test 14.",
"created_at": "2017-07-16T23:44:12+00:00"
},
{
"uuid": "3476bc69-3078-4693-9681-08dcf46ca438",
"body": "This is a test 13.",
"created_at": "2017-07-16T23:43:26+00:00"
},
{
"uuid": "a3175007-4be0-47d3-87d0-ecead1b65e3a",
"body": "This is a test 12.",
"created_at": "2017-07-16T23:43:21+00:00"
}
],
"meta": {
"limit": 5,
"offset": 0,
"next_offset": 5,
"previous_offset": null,
"next_page": "http://localhost:8080/api/v2/replies?_limit=5&_offset=5",
"previous_page": null
}
环路将呼吁meta > next_page
URL的AXIOS GET直到或者UUID在结果被发现或meta > next_page
是空(意味着没有更多的答复)。
你有什么试过的?到目前为止,看起来你还没有做出努力。 –
一些情况?这是Vue方法吗? – Bert
@DavidL我一直在玩它一段时间。我尝试了传统的'while'循环,由于AXIOS的承诺,这些循环不起作用。我也试过建立一个promise while循环(https://gist.github.com/tangzhen/7b9434df8beac308fd3e),但那也行不通。 – ATLChris