vue 文件上传

 <el-button @click="uploadtab" icon="el-icon-upload2">上传</el-button>
                  <input ref="excel-upload-input" style="display:none;" type="file" accept="" @change="handleClick" >
js
 upload(rawFile) {
      this.$refs['excel-upload-input'].value = null // fix can't select the same excel

      // if (!this.beforeUpload) {
      //   return
      // }
      const formData = new FormData();
      formData.append("file", rawFile);
       this.formData = formData

        console.log(this.formData,"990")

    },
    //文件上传
    handleClick(e) {
      const files = e.target.files
      const rawFile = files[0] // only use files[0]
     
      if (!rawFile) return
      this.upload(rawFile)
      
      // console.log(rawFile, "rawFile")
      // console.log(this.formData,"this.formData")
         generateVideo(
      this.formData
      ).then(res => {
        console.log(res)
      })

    },
    //点击上传按钮
    uploadtab() {

      this.$refs['excel-upload-input'].click()
     
    },
    
posted @ 2021-03-26 17:43  世界险恶你要内心强大  阅读(119)  评论(0编辑  收藏  举报