antd Upload(文件上傳)組件change事件怎么傳參;以及限制只上傳一個文件,再次上傳時替換(覆蓋)以前的文件



一:html結構(change事件傳參函數改變)

<a-upload name="file" :multiple="true" accept=".zip,.json" :before-upload="beforeUpload" :remove="projectHandleRemove" @change="value => handleChange(value, record)">
  <div @click="storageId(record)">
    <a-button :disabled="!record.value||!record.value2">
      <a-icon type="upload" /> 上傳動效文件
    </a-button>
  </div>
</a-upload>

二:js部分(handleChange函數接受參數改變)

// 文件上傳(value則是新傳遞過來的參數)
handleChange(data, value) {
        let that = this
        if (value.fileName) {
          value.fileName = ''
        }
        if (data.fileList.length > 1) {
//限制只上傳一個文件,再次上傳時則替換(覆蓋)以前的文件
          data.fileList.splice(0, 1)
        }
        this.$nextTick(() => {
          const formData = new FormData()
          formData.append('app', 'suprised-file')
          formData.append('file', data.file)
          const file = data.file
          wxUploadCos({
            file,
            cosCode: 'suprised-file',
            loadingTitle: '上傳中',
            originFileObj: data.file
          }).then(res => {
            if (res.data) {
              that.packageUrl = res.domain + res.path
              const params = {
                'columnId': that.columnId,
                'filePath': that.packageUrl,
                'width': value.value,
                'height': value.value2
              }
              postAction(that.url.uploading, params).then((res) => {
                that.$message.success(res.msg || '操作成功')
              }).catch((err) => {
                that.$message.warning(err.msg || '操作失敗,請稍后再試')
              })
            } else {
              that.$message.warning(String(res.msg) || '文件上傳失敗')
            }
          }).catch(() => {
            // that[picType + 'List'][0].status = 'error'
          })
        })
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM