7 字
1 分钟
Vue3使用el-upload上传图片
Vue
<el-form-item label="现场照片" prop="urls"> <el-upload v-model:file-list="imgFileList1" :action="action" :headers="imgToken" :on-success="handleSuccess1" list-type="picture-card" :before-upload="beforeAvatarUpload" :on-preview="handlePictureCardPreview" :on-remove="handleRemove1" > <el-icon> <Plus /> </el-icon> </el-upload></el-form-item>Data
//上传图片路径imgFileList1: [], //图片回显时使用imgFileListForm: [], //图片回显时使用piclist1: [], //图片回显时使用imgToken: { 'Blade-Auth': 'Bearer ' + JSON.parse(localStorage.getItem('saber-token')).content},limitImg: 10, //限制图片上传的数量action: `/api/blade-resource/oss/endpoint/put-file`,disabled: false,dialogImageUrl: '', //如果只是显示一张图片的话,可以直接对其赋值dialogVisible: falsemethods
beforeAvatarUpload(file) { const imgType = file.type === 'image/jpeg' || file.type === 'image/png'; const imgSize = file.size / 1024 / 1024 < 5; if (!imgType) { this.$utils.toast('图片只能是 JPG/PNG 格式!', 'error'); } if (!imgSize) { this.$utils.toast('图片大小不能超过 5MB!', 'error'); } return imgType && imgSize;},
handlePictureCardPreview(uploadFile) { this.dialogImageUrl = uploadFile.url; this.dialogVisible = true;},
handleRemove1(res) { console.log(res); let index = this.imgFileListForm.findIndex(e => e === res.url); this.imgFileListForm.splice(index, 1); console.log(this.imgFileListForm);},
handleSuccess1(res) { if (res.code === 200) { this.imgFileListForm.push(res.data.link); }},图片回显
//在查询到数据的地方if (this.form.images) { this.form.images.forEach(value => { this.imgFileList1.push({ url: value }); });} 分享
如果这篇文章对你有帮助,欢迎分享给更多人!
Vue3使用el-upload上传图片
https://blog.olinl.com/posts/vue-el-upload/ 相关文章 智能推荐
1
Vue3使用flv.js播放FLV视频流
代码开发实战 在Vue3 中使用 flv.js 播放 FLV 在线流的案例。
2
v-table组件添加序号
代码开发实战 在Vue3 中使用 el-table 组件添加序号的案例。
3
Vue3动态添加输入框并添加规则校验
代码开发实战 在Vue3 中动态添加输入框并添加规则校验的案例。
4
为了护住我那几块硬盘:我的 UPS 监控“三部曲
HomeLab 私有云 从 PVE 备注里的简陋脚本,到独立的 Node.js Web 监控页,记录一个 HomeLab 玩家的 UPS 监控进阶之路。
5
CI/CD 手册:Jenkins 自动化发布全流程
服务与应用运维 详细记录如何通过 Jenkins 搭建自动化流水线,实现 Node.js 前端项目与 Spring Boot 后端项目的打包、上传及一键部署。
