vue的change方法无法选择上传相同文件/el-uploader/type="file"



使用h5自带的input type=file时,使用change触发上传事件

<input class="exportss" type="file" id="fileExport" @change="handleFileChange" ref="inputer">
const inputDOM = this.$refs.inputer
      this.file = inputDOM.files[0] // 通过DOM取文件数据
      let size = Math.floor(this.file.size / 1024)
      this.formData = new FormData() // new一个formData事件
      this.formData.append('file',data.file)
      this.formData.append('xxx', xxx)
      this.formData.append('yyy', yyy)
    inputDatas(this.formData).then(response => {
    })

或者使用element的el-uploader

<el-upload
                  ref="upload"
                  :data="inputdata"
                  class="upload-demo"
                  :action="uploadUrl"
                  :show-file-list="false"
                  :on-preview="onpreview"
                  :before-upload="beforeAvatarUpload"
                  :on-error="handleError"
                  :on-success="handleSuccess"
                  :file-list="fileList">
                  <el-button :loading="loadings.isInport" icon="el-icon-upload" size="mini" type="primary">导入</el-button>
                </el-upload>

action为上传文件的地址,可手动拼接

若需要token验证,可添加:header="header"

headers: {
   Authorization: Cookies.get('token') 
   //从cookie里获取token,并赋值 Authorization ,而不是token
}



免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM