iview upload组件 上传 vue2 写法备份

  <Upload
          :action="urlDoMain + 'middle/bla'"
          :headers="{
            'Current-id': accountId,
            'Current-name': account,
          }"
      :max-size='10240'
      :on-exceeded-size='handleMaxSize' :format="['xlsx','xls']" accept=".xlsx,.xls" :multiple="false" :data="uploadData" :show-upload-list="false" :before-upload="handleBeforeUpload" :on-format-error="handleFormatError" :on-success="handleSuccess" style="display: inline-block; "> <i-Button type="primary" >上传</i-Button> </Upload>   handleMaxSize(file){
  // 提示报错 ,文件过大,请导入小于10m的文件
  }
handleBeforeUpload (file) { if (file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' || file.type === 'application/vnd.ms-excel') { // this.uploadData.file = file } }, handleFormatError (file) { this.$Message.error('文件 ' + file.name + ' 格式不正确,请上传.xls,.xlsx文件。') this.$nextTick(() =>{ this.uploadData = {} }) }, handleSuccess (res, file) { console.log(res, 'resimport') if (res.code == 0) { this.$Message.success('成功!'); } else { this.$Message.error(res.msg) } }, // 一个防抖写法 var debounce = (fn, delay) => { // 1.定义一个定时器, 保存上一次的定时器 let timer = null // 2.真正执行的函数 const _debounce = function() { // 取消上一次的定时器 if (timer) clearTimeout(timer) // 延迟执行 timer = setTimeout(() => { // 外部传入的真正要执行的函数 fn() }, delay || 1000) } return _debounce }; // 使用 funName: debounce(()=>{ // 执行操作 }, 300)

  

posted @ 2024-12-27 16:47  everseven  阅读(23)  评论(0)    收藏  举报