So I introduce another scheme here, that is, through the interceptor of vue router. The general logic is: click the button first, and the interceptor will intercept the request requested by the api. When it is judged that the request is a post request, the passed parameters will be encrypted by MD5 and encrypted into a unique signature string. Judging whether the request comes from the same api by this signature string. Save the signature in the session and judge whether it is multiple requests from a single api in a short time.
When the request is issued, we also send the signature string to the background of the requesting shepherd. At this time, we need to cooperate with the background to let the background developers return the signature string we passed to us in response headers again. The reason for this is that when this request has returned data, we need to remove the original restriction that prohibits the same api from requesting again. Through the signature returned by the background, you can know that the api is going to be released.
Note: No matter whether the request is timed out or wrong, the signature array in the cache should be cleared, otherwise the interface cannot be requested again next time.
Method of generating signature by MD5 encryption:
Here, the signature string is passed into the request header and then put back into the response header in the background. So as to judge whether the api request has been completed. If you don't want to pass the signature string into the background, you can also define a timer yourself. For example, set the timer to 5 seconds. If the signature string appears more than twice in 5 seconds, the request is only sent once, or it can be controlled to wait until the request is completely completed before sending the request. But there is a problem, that is, the time of the timer can't be determined, because the speed of interface request has a lot to do with the network, and there is no guarantee that the interface can complete the request within the time you set, so I used another method here.
In a complete api request, the signature string is passed in and returned: