elementui上传图片校验

<el-form-item label="门店海报:" prop="imageUrl" ref="image">
//自定义正则
var valiIcon = (rule, value, callback) => {
      // 图片验证
      if (!this.hasFmt) { //hasFmt设置为true/false
        callback(new Error("请上传门店海报"));
      } else {
        callback();
      }
//rules
imageUrl: [{ required: true, validator: valiIcon }]

//上传成功 handleAvatarSuccess(res) { this.hasFmt = true; this.$refs.image.clearValidate(); }, //删除成功 handleRemove(file) { this.hasFmt = false; this.$refs.image.validate(); }
//更改上传图片的名称
 beforeAvatarUpload1(file) {
      let current = new Date();
      this.postData1.key =
        "gymansium" +
        current.getFullYear() +
        current.getMonth() +
        current.getDate() +
        current.getHours() +
        current.getMinutes() +
        current.getSeconds() +
        current.getMilliseconds() +
        file.name.substr(file.name.lastIndexOf("."));}
posted @ 2019-12-10 15:04  写手在作画  阅读(3084)  评论(0编辑  收藏  举报