<input
type="file"
ref="fileInput"
style="display:none" //隐藏
accept="application/pdf,application/vnd.ms-powerpoint" //表示类型pdf、ppt
@change="fileChange">
这样写的fileInput清空不了this.$refs.fileInput.files
但是可以变相清空
<form id="fileForm">
<input
type="file"
ref="fileInput"
style="display:none"
accept="application/pdf,application/vnd.ms-powerpoint"
@change="fileChange">
</form>
把input放入到form中,然后清空form
document.getElementById('fileForm')&&document.getElementById('fileForm').reset();
据说还有另一种方法
document.getElementById('').outerHtml = document.getElementById('').outerHtml
但是如果使用了vue等其他框架,可能导致框架失效
小贴士:
inputtype类型:
http://www.w3school.com.cn/media/media_mimeref.asp
Extension MIME Type
.xlsx application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.xltx application/vnd.openxmlformats-officedocument.spreadsheetml.template
.potx application/vnd.openxmlformats-officedocument.presentationml.template
.ppsx application/vnd.openxmlformats-officedocument.presentationml.slideshow
.pptx application/vnd.openxmlformats-officedocument.presentationml.presentation
.sldx application/vnd.openxmlformats-officedocument.presentationml.slide
.docx application/vnd.openxmlformats-officedocument.wordprocessingml.document
.dotx application/vnd.openxmlformats-officedocument.wordprocessingml.template
.xlsm application/vnd.ms-excel.addin.macroEnabled.12
.xlsb application/vnd.ms-excel.sheet.binary.macroEnabled.12
如果有什么类型的文件不知道怎么写,可以上传文件用Fiddler抓包,文件一栏有content-type
Content-Disposition: form-data; name="binaryFile"; filename="新建文本文档.pptx"
Content-Type: application/vnd.openxmlformats-officedocument.presentationml.presentation
也就是accept中的type