Optimize progress bar
This commit is contained in:
parent
30b6644f21
commit
73a193d602
3 changed files with 21 additions and 5 deletions
|
|
@ -14,8 +14,14 @@ export function load (url, method = 'GET', loading) {
|
|||
return {
|
||||
then: function (success, error = function () {}) {
|
||||
if (loading) {
|
||||
const id = setInterval(_ =>
|
||||
loading({ step: Math.floor(Math.random() * 5 + 1) }),
|
||||
500)
|
||||
xhr.addEventListener('progress', loading)
|
||||
xhr.addEventListener('loaded', loading)
|
||||
xhr.addEventListener('loadend', evt => {
|
||||
loading(evt)
|
||||
clearInterval(id)
|
||||
})
|
||||
}
|
||||
xhr.addEventListener('error', error)
|
||||
xhr.addEventListener('load', ({ target }) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue