欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 建筑 > antDesignVue中a-upload上传组件的使用

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

2025/9/26 11:29:56 来源:https://blog.csdn.net/weixin_73610394/article/details/148302500  浏览:    关键词:antDesignVue中a-upload上传组件的使用
工作中需要使用上传组件,记录一下a-upload部分属性用法

1.showUploadList属性使用

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

2.如何实现回显功能

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

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

 // 编辑modifyFn(row) {this.fileList == []this.drawerTitle = "编辑"console.log(row);this.form = { ...row };// 使用 map 方法统一转换为标准的 fileList 格式const standardFileList = row.attachList.map(item => ({uid: item.id, // 使用原始数据的 id 作为 uidname: 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;},

可拖入上传附件组件代码

 <a-form-model-itemlabel="附件":label-col="{ span: 4 }":wrapper-col="{ span: 20 }"><a-upload-draggeraccept = "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地址

data() {return {uploadAction: "/uploadUrl",}
}

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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词