element之upload组件
最近做项目的附件上传,前端vue用到element的上传,记录下以备不时之需
View Code
单个文件上传的HTML。
下面为js脚本
export default { name: "schemeList", data() { return { loading: false, attachList:[], attachmentList: [], viwMode: "add", tableHeight: 160, uploadUrl: "/upload", form: { file: "" }, fileList: [], importHeaders: { enctype: "multipart/form-data" }, }; }, watch: {}, computed: {}, created: function() {}, mounted: function() { }, methods: { fileChange(file) { this.form.file = file.raw; this.fileList.push(file.raw); //上传文件变化时将文件对象push进files数组 //alert(file.raw); }, handleProgress(event, file, fileList) { alert("in progress"); }, submitUpload() { let that = this; debugger; if(that.form.file==null || that.fileList.length == 0){ that.$message.info("请选择要上传的文件!"); return; } that.loading=true; let formData = new FormData(); formData.append("file", that.form.file); //单个文件 that.$axios .post(that.uploadUrl, formData, { "Content-Type": "multipart/form-data" }) .then(res => { that.$refs.upload.clearFiles(); that.fileList = []; that.$message.success(res.data); console.log(res); }) .catch(err => { that.$message.error(err.data); console.log(err); }); }, handleRemove(file, fileList) { this.$refs.upload.clearFiles(); this.fileList = []; console.log(file, fileList); }, handlePreview(file) { alert(file); console.log(file); } } };
后端用到的是springboot,直接上代码
View Code
yml文件配置
View Code
相关推荐
学习web前端 2020-09-28
小焊猪web前端 2020-09-10
青蓝 2020-08-26
liduote 2020-08-13
Qc 2020-07-19
bowean 2020-06-28
starzhangkiss 2020-06-25
xustart0 2020-06-14
WinerChopin 2020-06-12
xxuncle 2020-06-05
WinerChopin 2020-06-03
wanwanwandj 2020-06-02
randeqi 2020-05-06
newcome 2020-04-29
chenhaotao 2020-05-10
那些年写过的代码 2020-05-09
前端学习笔记 2020-04-26
viewerlin 2020-04-20
学习web前端 2020-04-22