iview Upload上传

<FormItem label="脚本上传">
   <Upload
       class="uploadButton"
       ref="uploadButton"
       :on-success="handleUploadSuccess"
       :format="uploadFormat"
       :on-format-error="handleFormatError"
       :before-upload="handleClearFiles"
       action="http://file.cs/upload/files">                                                            
       <Button>Upload</Button>
   </Upload>
   <a class="exportBtn" v-if="this.modal.type === 'update'" v-bind:href="formItem.kafkaPsUrl">查看文件</a>
</FormItem>

methods () {
    handleChangeKafkaPsType (value) {    // 确定上传文件格式format
      if (value === 'python') {
        this.uploadFormat = ['py']
      } else if (value === 'sh') {
        this.uploadFormat = ['sh']
      } else {
        this.uploadFormat = ['js']
      }
    },
    handleUploadSuccess (res, file) {
        this.formItem.kafkaPsUrl = res.data.url
    },
    handleClearFiles () {   // 再次点击上传之前,清空之前已上传文件
      this.$refs.uploadButton.clearFiles()
    },
    handleFormatError (file) {
      this.$Message.warning({
        content: file.name + '文件类型不正确, 请选择' + this.uploadFormat.join(' or') + '类型',
        duration: 5
      })
    }
}

选择文件上传,上传到相应的服务器上,并返回查看该文件的url.

before-upload:上传文件之前,清空已上传文件,避免上传多个文件。

on-success文件上传成功时的钩子,返回字段为 response, file, fileList
on-format-error文件格式验证失败时的钩子,返回字段为file, fileList
before-upload上传文件之前的钩子,参数为上传的文件,若返回 false 或者 Promise 则停止上传
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值