时间:2021-05-26
话不多说 直接上代码
<el-upload :action="actionUrl" class="avatar-uploader" :multiple="false" name="files" ref="upload" :file-list="fileList" :on-preview="handlePreview" :on-success="handleSuccess" :before-upload ="beforeUpload" :http-request="httpRequest" :on-exceed="handleExceed" :on-change="handleChanged" accept=".csv,.xls,.xlsx" :auto-upload="false" > <el-button slot="trigger" size="small">选取文件</el-button> <el-button style="margin-left: 10px;" size="small" type="primary" @click="submitUpload">上传到服务器</el-button> <div slot="tip" class="el-upload__tip">只能上传csv/xslx/xsl文件,且不超过1M</div></el-upload>actionUrl: `${env.imgCaptchaUrl}**/upload`,fileList: [],handleChanged(file,fileList){ this.fileList = fileList }, handleExceed (file, fileList) { console.log(file); }, handleSuccess (res, file) { console.log(file); console.log(res); }, handlePreview(file){ console.log(file); }, beforeUpload (file) { if (file.size / 1024 / 1024 > 1) { Vue.$vux.toast.text('上传文件不超过1M') return false } var ext = file.name.substring(file.name.lastIndexOf('.') + 1) const extension = ext === 'csv' || ext === 'CSV' || ext === 'xlsx' || ext === 'xls' if (!extension) { Vue.$vux.toast.text('上传文件格式只能为csv、xlsx/xls') return false } }, httpRequest (opt) { const _this = this const file = opt.file Vue.$vux.toast.text('文件上传中...') var reader = new FileReader() reader.readAsDataURL(file) reader.onload = function (e) { let imgType = '' var ext = file.name.substring(file.name.lastIndexOf('.') + 1) if (ext === 'csv' ) { imgType = 'csv' } if (ext === 'xlsx' || ext === 'xls') { imgType = 'xlsx' } uploadCsv({ files: this.result.replace(`data:image/${imgType};base64,`, '') }) .then(res => { if (res.errno === 0) { Vue.$vux.toast.text('上传成功') _this.account.license_url = res.data.url } }) .catch(err => {}) } }, submitUpload(){ if(this.fileList.length==0){ this.successDialog = "请先选择文件"; this.sussAlog = true; return } this.$refs.upload.submit(); },onDownload(){ let start = "" let end = "" if(this.form.time){ start = parseTime(this.form.time[0]); end = parseTime(this.form.time[1]); } delete(this.form.time) Object.assign(this.form, { first_time: start, end_time: end , }); let { first_time, end_time, } = this.form; window.open(this.downUrl+"lm/downloadModel?"+ "&first_time="+first_time+ "&end_time="+end_time , '_blank'); },以上就是vue el-upload上传文件的示例代码的详细内容,更多关于vue el-upload上传文件的资料请关注其它相关文章!
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
一、思路,从后台获取七牛token,上传图片到七牛,获取返回图片路径放入el-upload。二、代码。点击上传只能上传jpg/png文件,且不超过500kbex
element-ui上传一张图片后隐藏上传按钮el-upload里面绑定一个占位class::class="{hide:hideUpload}"data里面初始
使用示例:upload.php文件上传上传类upload.class.php
本文实例为大家分享了vue.js异步上传文件的具体代码,供大家参考,具体内容如下上传文件前端代码如下:上传{{result}}正在上传中newVue({el:'
在该示例中,阐述了SpringMVC如何上传文件。1、上传页面upload.jspfile:2、controller配置文件