国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

vue el-upload上傳文件的示例代碼

瀏覽:88日期:2022-10-17 16:14:17

話不多說 直接上代碼

<el-upload :action='actionUrl' :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 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上傳文件的資料請關注好吧啦網其它相關文章!

標簽: Vue
相關文章:
主站蜘蛛池模板: 镇江市| 曲沃县| 东至县| 赤峰市| 连山| 兰州市| 营山县| 丰都县| 凤台县| 杨浦区| 久治县| 黎平县| 江城| 新竹市| 曲沃县| 凤山县| 滨海县| 依兰县| 三河市| 凤庆县| 陕西省| 太仆寺旗| 温州市| 恭城| 孟连| 天祝| 清原| 沂南县| 香格里拉县| 柏乡县| 喜德县| 土默特左旗| 榕江县| 萨嘎县| 米泉市| 丽江市| 嘉荫县| 左贡县| 易门县| 台北市| 余姚市|