vue 上傳圖片限制大小和格式

<div class="upload-box clear">
  <span class="fl">上傳圖片</span>
    <div class="artistDet-logo-box fl">
      <el-upload :action="this.baseServerUrl+'/fileUpload/uploadPic?filepath=artwork'" list-type="picture-card" :class="{disabled:uploadMainDisabled}"
     :file-list="imagelist" :on-preview="handlePictureMainPreview" :on-remove="handleMainRemove" :on-success="handleMainSuccess" :beforeUpload="beforeAvatarUpload">
</
el-upload> <el-dialog :visible.sync="dialogMainVisible" > <img width="100%" :src="dialogMainImageUrl" alt=""> </el-dialog> </div> </div>
beforeAvatarUpload(file) { var testmsg=file.name.substring(file.name.lastIndexOf('.')+1) const extension = testmsg === 'jpg' const extension2 = testmsg === 'png' const isLt2M = file.size / 1024 / 1024 < 10  
      if(!extension && !extension2) { this.$message({ message: '上傳文件只能是 jpg、png格式!', type: 'warning' }); } if(!isLt2M) { this.$message({ message: '上傳文件大小不能超過 10MB!', type: 'warning' }); } return extension || extension2 && isLt2M } ,
將beforeAvatarUpload加到methods裏面
相關文章
相關標籤/搜索