antDesignVue中a-upload上传组件的使用

工作中需要使用上传组件,记录一下a-upload部分属性用法
1.showUploadList属性使用

使用:showUploadList="{ showRemoveIcon: true ,showDownloadIcon: true }"属性可控制右侧下载,删除图标

2.如何实现回显功能

使用:defaultFileList="fileList" 格式传入参数实现

在编辑时需要回显附件信息,但是后端传参可能不符合组件标准接参数格式,导致无法回显

javascript 复制代码
 // 编辑
    modifyFn(row) {
      this.fileList == []
      this.drawerTitle = "编辑"
      console.log(row);
      this.form = { ...row };
      // 使用 map 方法统一转换为标准的 fileList 格式
      const standardFileList = row.attachList.map(item => ({
        uid: item.id, // 使用原始数据的 id 作为 uid
        name: item.fileName, // 使用原始数据的 fileName 作为文件名称
        status: 'done', // 文件状态,已完成
        url: item.filePath //`your_base_url/${item.filePath}` // 构建文件的访问 URL,需替换 your_base_url 为实际的文件存储基础 URL
      }));
      this.fileList = Object.assign([], standardFileList).map(item => {
        return Object.assign({}, item)
      })
      console.log("编辑传参", this.fileList);
      this.visible = true;
    },

可拖入上传附件组件代码

javascript 复制代码
 <a-form-model-item
              label="附件"
              :label-col="{ span: 4 }"
              :wrapper-col="{ span: 20 }"
            >
              <a-upload-dragger
              accept = "image"
                name="files"
               :action="uploadAction"
                listType="picture"
                :defaultFileList="fileList"
                @change="handleChange2"
                :showUploadList="{ showPreviewIcon: true,showRemoveIcon: true ,showDownloadIcon: true }"
              >
                <!-- :multiple="true"   -->
                <p class="ant-upload-drag-icon">
                  <a-icon type="inbox" />
                </p>
                <p class="ant-upload-text">
                  选择文件或拖入文件
                </p>
              </a-upload-dragger>
            </a-form-model-item>

在data中设置上传url地址

javascript 复制代码
data() {
   return {
           uploadAction: "/uploadUrl",
   }
}

在change事件中可对上传文件数据进行操作

相关推荐
沙蒿同学2 小时前
不引 Ghostscript:我用纯 Go 给 PDF 做了一场「压缩手术」
前端·后端·github
Linux_cy2 小时前
服务器管理工具哪个好用?我用了七八个
运维·服务器·javascript·python·ssh·面板·gmssh
变与不变8062 小时前
jQuery细节以及使用应用场景
前端·javascript·jquery
SailingCoder4 小时前
【封闭结束1】端到端交付:Agent 一次请求如何走完全链路
前端·安全·ai·面试·agent·harness
风骏时光牛马6 小时前
AI多模块协同自动化工作流
前端
zhangminghuan6 小时前
前端面试应对技巧
前端·面试·职场和发展
计算机魔术师6 小时前
潜伏14年的PHP致命洞,AI跑两天就交卷了
前端
IT_陈寒7 小时前
Vue的这个响应式陷阱我居然现在才发现
前端·人工智能·后端
Python自动化直播8 小时前
智能脚本批量管理拆开看:导入、导出、重写、试听
前端·python·ai·秒播