参考:https://www.jianshu.com/p/07c27e576b26

    css,把input隐藏,美化label即可。

    1. .inputfile {
    2. width: 0.1px;
    3. height: 0.1px;
    4. opacity: 0;
    5. overflow: hidden;
    6. position: absolute;
    7. z-index: -1;
    8. }

    html

    1. <input type='file' id='file' class='inputfile' webkitdirectory >
    2. <label for="file">Choose a file</label>

    js

    1. var files = [];
    2. $(document).ready(function(){
    3. $("#file").change(function(){
    4. files = this.files;
    5. });
    6. });
    7. $("#upload-btn").click(function(){
    8. var fd = new FormData();
    9. for (var i = 0; i < files.length; i++) {
    10. fd.append("files", files[i]);
    11. }
    12. });
    13. axios.post("url",data,{
    14. headers:{
    15. "Content-Type": "multipart/form-data",
    16. }
    17. });