流浪のwolf

卷帝

导航

element的图片上传预处理函数

 

 

 /** 图片格式和大小的控制 */
    beforeAvatarUpload (file) {
      // 允许上传 jpg 和 png 格式的图片
      const isJPG = file.type === "image/jpeg" || file.type === "image/png"
      // 限制图片的大小 2 MB
      const isLt2M = file.size / 1024 / 1024 < 2
      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG/PNG 格式!")
        return isJPG
      }
      if (!isLt2M) {
        this.$message.error("上传设备图片不能超出2M")
      }
      return isJPG && isLt2M
    },

 

posted on 2023-03-20 13:29  流浪のwolf  阅读(19)  评论(0编辑  收藏  举报