Forked from ljanecek/Vue.js, Nanobar, vue-resource, progress
Created
April 10, 2020 20:18
-
-
Save igolka97/79a716cfbdbadc56331c85b8086ac20d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
http: function(cont, options, next) { | |
if (cont.$root.$get('nanobar.value') > 1) { | |
return false; | |
} | |
cont.$root.$get('nanobar').go(20) | |
var _options = { | |
url: options.url, | |
method: options.methos ? options.methos : 'GET', | |
jsonp: 'callback', | |
xhr: { | |
onprogress: function(e) { | |
if (e.lengthComputable && !cont._isBeingDestroyed) { | |
cont.$root.$set('nanobar.max', e.total); | |
cont.$root.$set('nanobar.value', e.loaded); | |
cont.$root.$get('nanobar').go(Math.round((100 / e.total) * e.loaded)) | |
} else { | |
cont.$root.$set('nanobar.value', 0); | |
cont.$root.$get('nanobar').go(0) | |
this.abort() | |
} | |
}, | |
onloadstart: function(e) { | |
cont.$root.$set('nanobar.value', 0); | |
}, | |
onloadend: function(e) { | |
if(!cont._isDestroyed){ | |
cont.$root.$set('nanobar.value', 0); | |
} | |
}, | |
} | |
}; | |
var _options = _.extend(options, _options); | |
cont.$http(_options).then(function(res) { | |
if(!cont._isDestroyed){ | |
cont.$root.$set('nanobar.value', 0); | |
} | |
next(res.data) | |
}, function() { | |
next('error') | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment