"Anti-shake and throttling", a common problem, is also a high-frequency interview question.The big guys on the principle have already talked about it.Call it once in a short time, but try to write, setTimeout or set the switch.
My current approach is to encapsulate ajax or axios, and then add loading.
In this way, loading will pop up before each request, and loading disappears when the request callback comes back.
Pseudo code, taking axios as an example
//Request interceptor service.interceptors.request.use( config => { showLoading() return config }, error => { hideLoading() return Promise.reject(error) })//Response interceptor service.interceptors.response.use( response => { hideLoading() return response }, error => { hideLoading() return Promise.reject(error) })
0 Comments