点击上传文件按钮 beforeAvatarUpload方法自动上传1到多个图片php
<el-upload class="upload-demo" ref="upload" accept=".jpg" multiple :data="radio" :action="actionUrl" :on-preview="handlePreview" :on-remove="handleRemove" list-type="picture" :file-list="fileList" :before-upload="beforeAvatarUpload"> <el-button slot="trigger" size="small" :disabled="btnFlag" type="primary">上传文件</el-button> </el-upload>
**//上传画稿以前先判断画稿规格 再插oracle 再post到php
//为了解决onload异步使用promise**ajax
beforeAvatarUpload:function(file) { var _this = this; return new Promise(function(resolve, reject) { //为了解决onload异步使用promise if(file.name.length > 100){ _this.$alert(file.name+'图片名称字符长度超过100,不能上传!', '提示', {confirmButtonText: '肯定'}); reject(); return; } var reader = new FileReader(); var img_oracleFlag = false; reader.onload = function(event) { //onload是异步的 var image = new Image(); image.onload = function () { var width = this.width; var height = this.height; if (width>height && vm.radio.GGH=="小牌"){ _this.$alert(file.name+'不能上传!', '提示', {confirmButtonText: '肯定'}); reject(); return; }else if (width<height && vm.radio.GGH=="大牌"){ _this.$alert(file.name+'不能上传!', '提示', {confirmButtonText: '肯定'}); reject(); return; }else{ img_oracleFlag = true; //插入oracle $.ajax({ //必须使用同步ajax url : OracleInterface, type : 'post', dataType : 'json', async:false, data : {}, success : function(res) {}, error : function(data) {}, }) } resolve(); }; image.src = event.target.result; } reader.readAsDataURL(file); }); return true },