<input type="file" style="display: none;" id="file" ref="files" @change="upload">
使用type=file作为文件上传时,监听change事件来触发方法,但是两次上传同一个文件的话,change事件不会被触发,这时候就需要在每次上传文件完成操作之后手动清空input的值
方法如下:
clearInputFile(file){
var form = document.createElement('form');
document.body.appendChild(form);
var pos = file.nextSibling;
form.appendChild(file);
form.reset();
pos.parentNode.insertBefore(file, pos);
document.body.removeChild(form);
}
调用方法的时候需要将input传入
this.clearInputFile(document.getElementById("file"))