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

Vue2 ElementUI Upload组件http-request用法

一、示例代码

<template><el-uploadref="upload"action="":auto-upload="false":file-list="upload.fileList":accept="upload.accept":on-remove="removeFile":on-change="verifyFile":http-request="uploadFile":on-success="uploadSuccess":on-error="uploadError"><el-button slot="trigger" size="small">选择文件</el-button><el-button type="primary" size="small" :disabled="uploadDisabled" :loading="upload.loading" style="margin-left: 10px;" @click="confirmUpload">上传文件</el-button><div slot="tip" style="font-size: 12px;">只能上传xls/xlsx文件</div></el-upload>
</template>
<script>
export default {data () {upload: {loading: false,accept: '.xls,.xlsx',fileList: []}},computed: {uploadTypeErrorMessage () {return `只能上传 ${this.upload.accept.split(',')} 格式的文件`;},uploadDisabled () {return this.upload.fileList.length===0;}},methods: {removeFile () {let index = this.upload.fileList.findIndex(li =>li.uid===file.uid);index===-1?'':this.upload.fileList.splice(index, 1);},verifyFile (file) {if(file.status==='ready') {this.uploadDisabled?this.upload.fileList.push(file):this.upload.fileList.splice(0, 1, file);if(!['application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'].includes(file.raw.type)) {this.$message.error(this.uploadTypeErrorMessage);this.removeFile(file);}}},confirmUpload () {this.$refs.upload.submit();},uploadFile (options) {this.upload.loading = true;uploadFile({ //自定义接口file: options.file}).then(res => {options.onSuccess(res);}).catch(error => {options.onError(error);}).finally(() => {this.upload.loading = false;});},uploadSuccess (res) {},uploadError (error) {this.$message.error(error);}}
}
</script>

http://www.dtcms.com/a/342932.html

相关文章:

  • (二十一)深入了解AVFoundation-编辑:导出视频与格式转换的全流程
  • 全文 part1 - DGEMM Using Tensor Cores, and Its Accurate and Reproducible Versions
  • DeepSeek-V3.1 发布,迈向 Agent 时代的第一步
  • 0821 sqlite3_get_table函数(数据库函数的补充)
  • Nacos-9--认识Nacos中的Distro协议(Nacos高可用的实现原理)
  • visual studio编译的软件查找所依赖的运行库方法
  • 基于单片机智能路灯控制
  • 学习嵌入式第三十四天
  • 杂记 07
  • BGP高级特性
  • AI论文速读 | 多模态能否助力时间序列预测?时序预测中融合文本的边界与条件
  • Oracle CLOB类型转换
  • 数据分析三剑客
  • 如何解读京东按图搜索(拍立淘)API(jd.item_search_img)的返回值
  • AI大模型支持下的:CMIP6数据分析与可视化、降尺度技术与气候变化的区域影响、极端气候分析
  • JVM-(7)堆内存逻辑分区
  • 3个脱节,5大特征,1套方法:破解AI落地难题
  • 37、需求预测与库存优化 (快消品) - /供应链管理组件/fmcg-inventory-optimization
  • 【互动屏幕】大屏拼接在数字展厅展示上有哪些优势?
  • (CVPR-2025)通过频率分解实现身份保持的文本到视频生成
  • 【音视频】闭合GOP和开放GOP
  • 旅游小程序开发指南
  • 第三阶段数据库-5:数据库的主键,索引,约束,表间关系的图形化操作
  • 8.Shell脚本修炼手册---sed工具的基本使用
  • HarmonyOS 实战:6 种实现实时数据更新的方案全解析(含完整 Demo)
  • JavaScript中的深浅拷贝
  • Llama-Factory微调 Qwen2.5-VL-3B 模型
  • 人工智能未来趋势如何?
  • 【秋招笔试】2025.08.19百度秋招机考第一套
  • 算法训练营day57 图论⑦ prim算法精讲、kruskal算法精讲