文件上传图片形式
<template> <div> <el-upload style="margin-top: 10px;" class="upload-demo" list-type="picture-card" action="http://192.168.1.115:9999/sdfs/file/uploadFile" :on-remove="handleRemoveF" :on-success="handleSuccessF" :before-upload="handleBefore" :file-list="fileList"> 附件上传 <div slot="tip" class="el-upload__tip">文件大小不超过{{size}}MB</div> <div slot="file" slot-scope="{file}"> <div style="width: 146px;height: 146px;display: flex;justify-content: center;align-items: center; padding: 3px;"> <span>{{ file.name }}</span> </div> <span class="el-upload-list__item-actions"> <span class="el-upload-list__item-preview" @click="handleDown(file)"> <i class="el-icon-download"></i> </span> <span class="el-upload-list__item-delete" @click="handleRemoveF(file)"> <i class="el-icon-delete"></i> </span> </span> </div> </el-upload> </div> </template> <script> import util from '@/libs/util' export default { name: "UploadFile", props: { fileList:{ type: Array, default: () => { return [] } }, size:{ type: Number, default: () => { return 1 } } }, watch:{ }, data() { return { uploadUrl: util.baseUrl + '/sdfs/file/uploadFile', file:'' } }, methods: { handleRemoveF(file, fileList) { for(let i in this.fileList){ if(file.data.filePath==this.fileList[i].data.filePath){ this.fileList.splice(i,1) } } }, handleDown(file) { window.open(util.baseUrl + '/sdfs/file/download?filePath=' + file.data.filePath) }, handleBefore(file){ const isLt2M = file.size / 1024 / 1024 < this.size; if (!isLt2M) { this.$Message.error('上传文件大小不能超过'+ this.size +'MB!') } return isLt2M; }, handleSuccessF(res, file) { res.name = file.name this.fileList.push(res) } } } </script> <style scoped> </style>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
2021-12-15 uni-app的一些方法