点击上传文件按钮 beforeAvatarUpload方法自动上传1到多个图片

<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**

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
},

本文固定链接: http://www.js-code.com/vue-js/vue-js_17199.html