Optimize progress bar

This commit is contained in:
qingwei.li 2016-12-19 21:52:33 +08:00
commit 73a193d602
3 changed files with 21 additions and 5 deletions

View file

@ -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 }) => {