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("."));}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM