vue + Element上传多个文件,支持删除重新上传,上传后将后台返回的URL发送给后台存到数据库
发布日期:2022-02-24 01:06:50
浏览次数:20
分类:技术文章
本文共 2776 字,大约阅读时间需要 9 分钟。
vue + Element上传多个文件,支持删除重新上传,上传后将后台返回的URL发送给后台存到数据库
点击上传
data () { return { visible: false, doUrl: '', fileList: [], dataForm: { id: '', version: '', closeNum: 1, settleIds: '', dealResult: 1, sendObj: '区农经站主管部门', promptRemark: '', attachmentUrls: '' } } },
methods: { init () { this.doUrl = `${ window.SITE_CONFIG['apiURL']}/sys/oss/upload?token=${ localStorage.getItem('token')}` this.visible = true }, handleExceed (files, fileList) { return this.$message.warning('当前限制最多可以上传3个文件') }, //文件删除的钩子函数(该钩子默认执行 :on-remove="handleRemove"和该钩子不写也行) handleRemove (file,fileList) { this.fileChange(fileList); }, //文件上传成功后的钩子函数 uploadSuccess (res, file, fileList) { this.fileChange(fileList); }, fileChange(file,fileList) { let tempStr = ''; if (fileList.length > 0) { for (let i = 0; i < fileList.length; i++) { if (fileList[i].response) { if (fileList[i].response.code === 0) { if (i === 0) { tempStr += fileList[i].response.data.src; } else { tempStr += ',' + fileList[i].response.data.src; } } } else if (fileList[i].status && fileList[i].status === 'success') { if (i === 0) { tempStr += fileList[i].url; } else { tempStr += ',' + fileList[i].url; } } } } this.dataForm.attachmentUrls = tempStr; }, // 上传图片前调用方法 beforeUploadPicture (file) { const is10M = file.size / 1024 / 1024 < 10 if (!is10M) { this.$message.error('文件大小不能超过10MB!') return false } return true }, // 表单提交 dataFormSubmitHandle: debounce(function () { this.$refs.dataForm.validate((valid) => { if (!valid) { return false } if (!this.dataForm.id) { return false } this.$http.post('townEarlyWarningEvent/townEarlyWarningEvent/byHandle', this.dataForm).then(({ data: res }) => { if (res.code !== 0) { return this.$message.error(res.msg) } this.$message({ message: this.$t('prompt.success'), type: 'success', duration: 500, onClose: () => { this.visible = false this.$emit('refreshDataList') } }) }).catch(() => { }) }) }, 1000, { leading: true, trailing: false }) }
转载地址:https://blog.csdn.net/weixin_45877686/article/details/114591007 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月18日 11时46分51秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
委托与事件(浅度分析)—事件
2019-04-26
.NET框架
2019-04-26
VB.NET入门
2019-04-26
七层登录
2019-04-26
Polar bear and air-conditioner
2019-04-26
不加注解引起的500错误
2019-04-26
PB使用专用接口连接SQL Server
2019-04-26
PB中创建需要带参数查询的DataWindow
2019-04-26
idea如何设置自动换行
2019-04-26
Java—JDBC入门
2019-04-26
java各工具类Utils
2019-04-26
java8 集合分组(根据集合中对象中时间字段的月份分组)
2019-04-26
Linux常用快捷键和基本命令
2019-04-26
Linux上安装jdk1.8和配置环境变量
2019-04-26
A表中存有B表的多个主键,逗号隔开,B表进行删除时,要判断B表是否绑定A,怎么实现?
2019-04-26
centos环境下docker安装redis并挂载外部配置和数据
2019-04-26
maven中的setting.xml 配置文件
2019-04-26
MySQL的Limit详解
2019-04-26