欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 养生 > 使用 ElementUI 和 Spring 实现稳定可靠的文件上传和下载功能

使用 ElementUI 和 Spring 实现稳定可靠的文件上传和下载功能

2025/2/12 19:08:51 来源:https://blog.csdn.net/qiuyufeng/article/details/145458571  浏览:    关键词:使用 ElementUI 和 Spring 实现稳定可靠的文件上传和下载功能

前端(ElementUI)

1. 文件上传

  • 使用 el-upload 组件
  • 配置上传接口
  • 处理上传成功和失败
<template><div><el-uploadclass="upload-demo"action="http://your-server-url/upload":on-success="handleSuccess":on-error="handleError":before-upload="beforeUpload":show-file-list="true":auto-upload="true":headers="headers"><el-button size="small" type="primary">点击上传</el-button><div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div></el-upload></div>
</template><script>
export default {data() {return {headers: {Authorization: 'Bearer ' + localStorage.getItem('token') // 如果需要认证}};},methods: {handleSuccess(response, file, fileList) {this.$message.success('文件上传成功');console.log('上传成功', response);},handleError(err, file, fileList) {this.$message.error('文件上传失败');console.error

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com