const xhr = new XMLHttpRequest();
xhr.upload.onprogress = function(e) {
// lengthComputable 是一个布尔值 判断当前资料是否可计算长度
if (e.lengthComputable) {
// loaded 代表已上传的资源字节, total 是资源总共的字节
const precent = Math.ceil((e.loaded/e.total)*100)
}
}
原文:https://www.cnblogs.com/tonyjia520/p/14495720.html