input文件上传代码片段

需求:自己留个记录

<div class="button—2" @click="uploadFile">
  <input type="file" ref="file" multiple="multiple" @change="fileChange" style="display:none">
   上传
 div>
async uploadFile() {
  this.$refs.file.dispatchEvent(new MouseEvent("click"));
},
async fileChange(event) {
  const file = event.target.files[0];
  const result = await fileUploadToFolder({
    folder: this.currentId,
    file: file
  });
  if (result) {
    this.$refs.file.value = "";
    event.target.value = 0;
  }
}

你可能感兴趣的:(vue)