In Vue, according to the returned information of axios, it is sometimes necessary to re-request what has just been sent, how to implement it

When using axios to send a request in

vue, it is sometimes necessary to resend the request according to the returned information. Is there any way to achieve this? please give me some advice. Xiaobai sometimes doesn"t quite understand. Please speak to me. You"d better give me some pseudo code. Thank you

.
Jun.22,2022

this kind of requirement scenario is still common in tables (such as status refresh). The common practice is to use a timer to send the request, and then choose whether to destroy the timer according to the return


you can encapsulate this axios request as a function, and if the returned message requires a resend request, then call this function recursively
like this

function request() {
    axios.get(xxx)
    .then(res => {
        // 
        if (res.status) {
            request()
        }
    })
}

request()
Menu