vue el-upload上传文件的示例代码
话不多说直接上代码
选取文件 上传到服务器 只能上传csv/xslx/xsl文件,且不超过1M
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') returnfalse } varext=file.name.substring(file.name.lastIndexOf('.')+1) constextension= ext==='csv'|| ext==='CSV'|| ext==='xlsx'|| ext==='xls' if(!extension){ Vue.$vux.toast.text('上传文件格式只能为csv、xlsx/xls') returnfalse } }, httpRequest(opt){ const_this=this constfile=opt.file Vue.$vux.toast.text('文件上传中...') varreader=newFileReader() reader.readAsDataURL(file) reader.onload=function(e){ letimgType='' varext=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(){ letstart="" letend="" 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'); },
以上就是vueel-upload上传文件的示例代码的详细内容,更多关于vueel-upload上传文件的资料请关注毛票票其它相关文章!