vue上传附件、导入文件

:action="上传地址"  
 :data="fileData" //附件项
listFileList=上传的文件列表

<el-upload :action="uploadUrl" style="margin-left: 10px;" name="multipartFile "
                                    :on-success="uploadIntegritySuccess" :before-upload="beforeUpload" :data="fileData"
                                    accept=".pdf," :file-list="replyFileList" :limit="1" :on-exceed="handleExceed"
                                    :on-remove="handleIntegrityRemove">

                                    <el-button size="small" type="primary">点击上传</el-button>
                                </el-upload>
// 谈话上传前
        beforeUpload(file) {
            // 特殊字符
            if (file.name.indexOf('#') > -1 || file.name.indexOf('%') > -1) {
                this.$message.info('上传图片文件名称不能包含"%、#"等特殊字符')
                return false
            }
        },
//上传成功

uploadIntegritySuccess(res, file, fileList) {
            if (res.success) {
                this.ruleForm.replyOpinionUrl = res.obj
                this.ruleForm.coverName = file.name
            } else {
                this.$message.error(res.msg)
                this.ruleForm.replyOpinionUrl = ''
                this.ruleForm.coverName = ''
            }

        },

 //上传文件限制
        handleExceed() {
            this.$message.warning(`只能上传1个文件`);
        },

//移出
handleListRemove() {
            this.deleteOssFile(this.ruleForm.identificationUrl)
                .then(() => {
                    this.ruleForm.identificationUrl = ''
                    this.ruleForm.identificationName = ''
                })

        },

导入附件

<el-upload
          :action="uploadUrl" //地址
          ref="upload"
          name="file"
          :limit="1"
          :data="{ type: 2 }"
          :show-file-list="false"
          :auto-upload="false"
          :on-change="uploadExcel"
          accept=".xls,.xlsx"
        >
          <el-button type="primary" plain icon="el-icon-upload2">导入</el-button>
        </el-upload>

//上传文件
      uploadExcel(file) {
        const isLt500M = file.raw.size / 1024 / 1024 < 500        if (!isLt500M) {
          this.$refs.upload.clearFiles()
          return this.$message.info('上传文件大小不能超过 500MB!')
        }
        this.importExcel(file.raw)
      },
      // 导入
      importExcel(value) {
        this.isShowMask = true
        const formdata = new FormData()
        formdata.append('file', value)
        parkEconomyDataServer.enterpriseEconomy
          .importEnterpriseEconomy(formdata)
          .then((res) => {
            if (res.success) {
              if (res?.obj) {
                this.enterpriseEconomyData = res.obj
                this.isShowDialog = true
              }
            } else {
              this.$message.error(res.msg)
            }
            this.isShowMask = false
            // 清除浏览器上传历史记录文件(必须调用上传不管成功失败,否则上传一次之后不能继续)
            this.handleClear()
          })
          .catch((error) => {
            this.$message.error(error.message)
            this.isShowMask = false
          })
      },
      // 清除浏览器上传历史记录文件
      handleClear(res, file) {
        this.$refs.upload.clearFiles()
      },

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值