使用 onUploadProgress
实现
let self = this this.axios.put(this.uploadUrl, this.files[0], { headers: { 'Content-Type': 'multipart/form-data' }, transformRequest: [function (data) { return data }], onUploadProgress: progressEvent => { let complete = (progressEvent.loaded / progressEvent.total * 100 | 0) + '%' self.uploadMessage = '上传 ' + complete } }) .then((response) => { if (response.status === 200) { self.uploadMessage = '上传成功!' } })
axios.put
默认参数上传文件到服务器
this.axios.put(uploadImgUrl, files) .then((response) => { console.log(response) })