当前位置: 首页 > news >正文

vant拍摄视频上传以及多张图片上传

数据定义

data() {return {fileList: [],vedioList: [],formData: '',fileTypes: 'image/png,image/jpeg,image/jpg,image/jpeg',}
},
beforeMount() {this.formData = new FormData()
},

拍摄视频上传

<van-uploaderv-if="radio === '1'"v-model="vedioList"accept="video/*":max-count="1":max-size="52428800"capture="camera":after-read="(file, detail) => uploadAfterReadFnVedio(file, detail, '现场视频')":before-delete="(e, $event) => { uploaderBeforeDeleteVedio(e, $event) }">
</van-uploader>

拍摄视频上传事件

uploadAfterReadFnVedio(file, { index }, name) {this.formData.set('files', file.file)file.status = 'uploading'file.message = '上传中...'// 此时可以自行将文件上传至服务器UploadVideo(this.formData).then((res) => {this.vedioList.push({ url: res.data[0], key: res.data[0], name: name })this.vedioList.splice(index, 1)}).catch((_) => {// eslint-disable-next-line no-param-reassignfile.status = 'failed'// eslint-disable-next-line no-param-reassignfile.message = '上传失败'})
},

选择多张图片上传

<van-uploaderv-model="fileList":accept="fileTypes"multiple:max-size="5242880":max-count="6":after-read="(file, detail) => uploadAfterReadFn(file, detail, reqSubmitSBSJSBGZ.ListPic, '现场图片')":before-delete="(e, $event) => { uploaderBeforeDelete(e, $event, reqSubmitSBSJSBGZ.ListPic) }">
</van-uploader>

多张图片上传事件

uploadAfterReadFn(file, { index }, list, name) {const types = this.fileTypes.split(',')// 判断是一张还是多张图片if (Array.isArray(file)) {file.forEach(item => {if (!types.find((v) => v === item.file.type)) {this.$toast({type: 'fail',message: '请上传正确的图片',className: 'noticeWidth'})}if (item.file.size <= 5 * 1024 * 1024) {this.$toast({type: 'fail',message: '上传文件超过5M',className: 'noticeWidth'})}this.formData.set('files', item.file)// eslint-disable-next-line no-param-reassignitem.status = 'uploading'// eslint-disable-next-line no-param-reassignitem.message = '上传中...'// 此时可以自行将文件上传至服务器UploadFile(this.formData).then((res) => {this.fileList.push({ url: item.content, isImage: true, key: res.data[0] })this.fileList.splice(index, 1)list.push({ url: res.data[0], isImage: true, key: res.data[0] })}).catch((_) => {// eslint-disable-next-line no-param-reassignitem.status = 'failed'// eslint-disable-next-line no-param-reassignitem.message = '上传失败'})})} else {if (!types.find((v) => v === file.file.type)) {this.$toast({type: 'fail',message: '请上传正确的图片',className: 'noticeWidth'})return false}if (file.file.size > 5 * 1024 * 1024) {this.$toast({type: 'fail',message: '上传文件超过5M',className: 'noticeWidth'})return false}this.formData.set('files', file.file)// eslint-disable-next-line no-param-reassignfile.status = 'uploading'// eslint-disable-next-line no-param-reassignfile.message = '上传中...'// 此时可以自行将文件上传至服务器UploadFile(this.formData).then((res) => {this.fileList.push({ url: file.content, isImage: true, key: res.data[0] })this.fileList.splice(index, 1)list.splice(index, 1, {url: res.data[0],value: res.data[0],key: name})// eslint-disable-next-line no-param-reassignlist = [...list]}).catch((_) => {// eslint-disable-next-line no-param-reassignfile.status = 'failed'// eslint-disable-next-line no-param-reassignfile.message = '上传失败'})}
},

toast样式

<style>
.noticeWidth{min-width: 150px !important;line-height: 34px;font-size: 24px;
}
</style>
http://www.lryc.cn/news/393055.html

相关文章:

  • 如何用手机拍出高级感黑白色调照片?华为Pura70系列XMAGE演绎黑白艺术
  • Cartographer前后端梳理
  • Java面试题系列 - 第3天
  • 【Spring Boot】Spring Boot简介
  • Akamai+Noname强强联合 | API安全再加强
  • 第四届BPAA算法大赛成功举办!共研算法未来
  • 2024第三届中国医疗机器人大会第一轮通知
  • 常见算法和Lambda
  • 自动缩放 win7 远程桌面
  • 微机原理与单片机 知识体系梳理
  • 低音炮内存卡格式化后无法播放音乐文件
  • 手动将dingtalk-sdk-java jar包打入maven本地仓库
  • C++:构造函数是什么东西
  • 工作两年后,我如何看待设计模式
  • 01 Web基础与HTTP协议
  • Java求自然常数e的近似值(课堂实例1)
  • 简过网:什么是咨询工程师?我不允许还有人不知道!
  • 数据泄露时代的安全之道:访问认证的重要性
  • XLSX + LuckySheet + LuckyExcel + Web Worker实现前端的excel预览
  • Java版本迭代的过程(Java面经)
  • 深入了解java锁升级可以应对各种疑难问题
  • C++初学者指南-4.诊断---基础:警告和测试
  • docker使用镜像jms_all部署jumpserver
  • 在Java项目中集成单元测试与覆盖率工具
  • CTF实战:从入门到提升
  • Spring Boot集成olingo快速入门demo
  • GPT对话代码库——HAL库下 USART 的配置及问题(STM32G431CBT6)
  • ExoPlayer架构详解与源码分析(14)——ProgressiveMediaPeriod
  • docker部署kafka(单节点) + Springboot集成kafka
  • 一.1.(3)半导体二极管基本电路的分析方法及常见应用电路