zoukankan      html  css  js  c++  java
  • ant-design-vue 上传图片组件


    <a-upload name="multipartFile" listType="picture-card" class="avatar-uploader" :showUploadList="false" action="自己的api" headers="{token:'token值'}" :beforeUpload="beforeUpload" @change="handleFrontImgChange"> <a-popover v-if="idCardFront" placement="top"> <template slot="content"> <img style="100%" :src="idCardFront" alt="正面" /> </template> <a-icon v-if="loadingFront" type="loading" /> <img v-else style="100%" :src="idCardFront" alt="正面" /> </a-popover> <div v-else> <a-icon :type="loadingFront ? 'loading' : 'plus'" /> <div class="ant-upload-text">上传</div> </div> </a-upload>

      

        handleFrontImgChange (info) {
          if (info.file.status === 'uploading') {
            this.loadingFront = true;
            return;
          }
          let res = info.file.response // 后端返回的数据
          if (info.file.status === 'done') {
            this.loadingFront = false;
    
            if (res.status && res.status != '1') {
              this.$message.error(res.info)
              return
            }
    
            this.idCardFront = res.data.fileName
          }
          if (info.file.status === 'error') {
            this.$message.error(res.error)
          }
        },
        beforeUpload (file) {
          const isJPG = file.type === 'image/jpeg' || file.type === 'image/png';
          if (!isJPG) {
            this.$message.error('仅支持jpeg/png格式!');
          }
          const isLt2M = file.size / 1024 / 1024 < 5;
          if (!isLt2M) {
            this.$message.error('上传不能超过5MB!');
          }
          return isJPG && isLt2M;
        }
    

      

  • 相关阅读:
    【Gym
    [matlab工具箱] 曲线拟合Curve Fitting
    数学建模 常用
    “这么多人给我作证,我不怕”
    超星尔雅刷课辅助
    细思《都挺好》
    P5173 传球
    [ICPC 北京 2017 J题]HihoCoder 1636 Pangu and Stones
    CF 1131C Birthday
    CF 634A Island Puzzle
  • 原文地址:https://www.cnblogs.com/xiaoyun1121/p/11899734.html
Copyright © 2011-2022 走看看