提交 5fc59a65 编写于 作者: M Matt Zabriskie

Resolving merge conflicts

......@@ -257,7 +257,13 @@ These are the available config options for making requests. Only the `url` is re
xsrfCookieName: 'XSRF-TOKEN', // default
// `xsrfHeaderName` is the name of the http header that carries the xsrf token value
xsrfHeaderName: 'X-XSRF-TOKEN' // default
xsrfHeaderName: 'X-XSRF-TOKEN', // default
// `progress` allows handling of progress events for 'POST' and 'PUT uploads'
// as well as 'GET' downloads
progress: function(progressEvent) {
// Do whatever you want with the native progress event
}
}
```
......
......@@ -26,7 +26,13 @@
data.append('foo', 'bar');
data.append('file', document.getElementById('file').files[0]);
axios.put('/upload/server', data)
var config = {
progress: function(progressEvent) {
var percentCompleted = progressEvent.loaded / progressEvent.total;
}
};
axios.put('/upload/server', data, config)
.then(function (res) {
output.className = 'container';
output.innerHTML = res.data;
......@@ -40,4 +46,3 @@
</script>
</body>
</html>
......@@ -151,6 +151,15 @@ module.exports = function xhrAdapter(resolve, reject, config) {
requestData = new DataView(requestData);
}
// Handle progress if needed
if (config.progress) {
if (config.method === 'post' || config.method === 'put') {
request.upload.addEventListener('progress', config.progress);
} else if (config.method === 'get') {
request.addEventListener('progress', config.progress);
}
}
// Clean up request
requestData = (requestData === undefined)
? null
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册