(function () {
var output = document.getElementById('output');
document.getElementById('upload').onclick = function () {
var data = new FormData();
data.append('foo', 'bar');
data.append('file', document.getElementById('file').files[0]);//获取文件
var config = {
onUploadProgress: function(progressEvent) { //上传进度
var percentCompleted = Math.round( (progressEvent.loaded * 100) / progressEvent.total );
}
};
axios.put('/upload/server', data, config)
.then(function (res) {
output.className = 'container';
output.innerHTML = res.data;
})
.catch(function (err) {
output.className = 'container text-danger';
output.innerHTML = err.message;
});
};
})();
axios上传文件
最新推荐文章于 2024-09-28 14:59:20 发布