https://zinoui.com/blog/ajax-request-progress-bar
<template>
<div style="padding:20px">
<input ref="file" id="file" type="file" @change="change">
<div>上传文件</div>
<progress id="progress" value="" max=""></progress>
<div id="progressBar_value"></div>
<div id="progressBar_max"></div>
</div>
</template>
<script>
export default {
methods: {
change(input) {
let file = input.currentTarget;
this.upload(file.files[0])
},
upload(file) {
const formData = new FormData();
formData.append("file", file);
const progressBar = document.getElementById("progress")
const progressBar_value = document.getElementById("progressBar_value");
const progressBar_max = document.getElementById("progressBar_max");
const xhr = new XMLHttpRequest();
xhr.open("POST", "/good4/test/upload.php", true);
xhr.upload.onprogress = function (e) {
if (e.lengthComputable) {
progressBar.max = e.total;
progressBar.value = e.loaded;
progressBar_value.innerHTML = `${(e.loaded / 1024 / 1024).toFixed(3)}MB`;
progressBar_max.innerHTML = `${(e.total / 1024 / 1024).toFixed(3)}MB`;
}
}
xhr.upload.onloadstart = function (e) {
progressBar.value = 0;
}
xhr.upload.onloadend = function (e) {
progressBar.value = e.loaded;
}
xhr.send(formData);
}
}
}
</script>
<?PHP
move_uploaded_file($_FILES["file"]["tmp_name"], "log/".$_FILES["file"]["name"])
?>