首页 > 其他分享 >element-ui 文件上传多个

element-ui 文件上传多个

时间:2022-12-15 14:57:18浏览次数:39  
标签:dom res fileList element item ui data file 上传

 


 


<template> <div> <el-upload ref="upload" :action="action" :limit="5" :file-list="fileList" :on-exceed="handleExceed" :on-remove="handleRemove" :on-success="handleSuccess" :before-upload="beforeUpload" :disabled="disabled" :on-preview="hanleOnpreview" > <el-button size="small" type="primary">点击上传</el-button> <div slot="tip" class="el-upload__tip"> 可以上传jpg/png/Jpeg/word/pdf/excel等格式文件,单个文件不可超过5M,附件不可超过5个 </div> </el-upload> </div> </template> <script> // /file/download // 下载 import { fileDownload } from "@/api/announcement-manage"; export default { props: { file: { type: Array, default: () => { return []; }, }, uploadType: { type: String, default: () => { return ""; }, }, disabled: { type: Boolean, default: () => { return false; }, }, }, data() { return { // action: "https://www.xwqyy.com/filemanage/file/upload?project=customer", action: this.$util.baseUrl + "/sdfs/file/uploadFile", // 上传图片的url fileList: [], }; }, mounted() { this.fileList = this.file.length > 0 ? this.file : []; }, watch: { file: { handler(newData, oldData) { this.fileList = newData.length > 0 ? newData : []; }, deep: true, }, }, methods: { handleRemove(file, fileList) { console.log("file111", fileList); for (let item of fileList) { item.fileName = item.name; item.filePath = item.url; } if (this.uploadType == "fileList") { console.log("file222", fileList); this.$emit("getFileList", fileList); } }, handleSuccess(res, file, fileList) { // res.data.name = res.data.fileName; // res.data.url = res.data.filePath; // this.fileList.push(res.data); let imgarr = []; for (let item of fileList) { item.fileName = res.data.fileName; item.filePath = res.data.filePath; imgarr = fileList; } if (this.uploadType == "fileList") { this.$emit("getFileList", imgarr); } }, beforeUpload(file) { const isLt5M = file.size / 1024 / 1024 < 5; if (!isLt5M) { this.$message.error("上传图片大小不能超过5MB!"); } return isLt5M; }, handleExceed(files, fileList) { this.$message.warning("附件不能超过5个"); }, //点击下载 hanleOnpreview(file) { fileDownload({ filePath: file.url, }).then((res) => { this.downFile(res.data, file.name); }); }, //下载乱码转换 downFile(content, fileName) { const dom = document.createElement("a"); // 隐藏的a标签,href为输出流 const blob = new Blob([content], { type: "application/vnd.ms-excel", // 创建一个类文件对象:Blob对象表示一个不可变的、原始数据的类文件对象 }); const url = window.URL.createObjectURL(blob); // 生成一个Blob对象 dom.style.display = "none"; dom.href = url; document.body.appendChild(dom); dom.setAttribute("download", fileName); dom.click(); document.body.removeChild(dom); URL.revokeObjectURL(url); }, }, }; </script> <style lang="less"> .disabled .el-upload--picture-card { display: none; } </style>

 

标签:dom,res,fileList,element,item,ui,data,file,上传
From: https://www.cnblogs.com/Byme/p/16985015.html

相关文章

  • uview图片上传多张
    <template><viewclass="contain-box"><u-navbar:title="title":is-back="true"back-icon-color="#fff":background="background"......
  • elment-ui 文件上传
      <template><div><el-uploadref="upload":action="action":limit="1":file-list="fileList":on-exceed="handleExcee......
  • 关于使用arduino控制舵机的程序,验证成功。
    方案一:使用PWM波库控制-----------------------------------include<Servo.h>//加载文件库intpos=0;Servomyservo;voidsetup(){myservo.attach(9,......
  • c# web 大文件上传源代码
    ​ 第一点:Java代码实现文件上传FormFilefile=manform.getFile();StringnewfileName= null;Stringnewpathname= null;StringfileAddre= "/numUp";try{......
  • [WPF] MediaElement播放HDR视频泛黄、颜色显示不正确应该如何解决?
    当我们在使用MediaElement控件播放HDR视频时会遇到颜色发灰、泛黄的情况,难道是因为控件做的有问题?其实并不是程序问题,只是我们普通的应用程序工作在8bit色深的环境中,而HDR......
  • .net web 大文件上传源代码
    ​ javaweb上传文件上传文件的jsp中的部分上传文件同样可以使用form表单向后端发请求,也可以使用ajax向后端发请求    1.通过form表单向后端发送请求     ......
  • ui和ux
    ################                             f=@(x)1./(sqrt(x.*exp(x)).*sqrt(2*pi))quadl(f,0,10.82)......
  • WPF学习-UI布局
    (1)WPF布局原则:1.不用显示的方式设置元素的尺寸。2.不使用屏幕坐标来指定位置。(2)常用布局控件:Grid容器、StackPanel、DockPanel、WrapPanel、UniformGrid、Canvas、In......
  • vue-element-admin 安装第三包(npm install)时报错
    主要报错信息:ls-remotessh://[email protected]/adobe-webplatform/eve.gitnpmERR!code128npmERR!gitdeppreparationfailednpmERR!commandD:\nodejs\node.exe......
  • 瓴羊Quick BI 权限管理:商业智能工具的领头羊
    当前,很多企业想通过引进商业智能工具让内部数据分析效率与智能化水平提高,建立起一套有效的数据分析与运行管理体系。在选择BI工具时,运算速度和功能多样性是考虑最多的,其他几......