<Upload :action="urlDoMain + 'middle/bla'" :headers="{ 'Current-id': accountId, 'Current-name': account, }" :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> 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)
标签:vue2,debounce,upload,timer,file,res,Message,上传,iview From: https://www.cnblogs.com/everseventh/p/18636173