参考:https://www.jianshu.com/p/07c27e576b26
css,把input隐藏,美化label即可。
.inputfile {
width: 0.1px;
height: 0.1px;
opacity: 0;
overflow: hidden;
position: absolute;
z-index: -1;
}
html
<input type='file' id='file' class='inputfile' webkitdirectory >
<label for="file">Choose a file</label>
js
var files = [];
$(document).ready(function(){
$("#file").change(function(){
files = this.files;
});
});
$("#upload-btn").click(function(){
var fd = new FormData();
for (var i = 0; i < files.length; i++) {
fd.append("files", files[i]);
}
});
axios.post("url",data,{
headers:{
"Content-Type": "multipart/form-data",
}
});