ant-design form表单校验upload组件

      <a-form-model ref="myForm" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
           <a-form-model-item label="签名图片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="signPath2">
              <img :src="imageUrl" alt="" v-if="imageUrl" class="img-sign" />
              <a-upload name="file" :showUploadList="false" :multiple="false" accept="image/*" ="handleSignUpload"
                :action="uploadUrl" :headers="tokenHeader">
                <a-button type="primary" v-if="!imageUrl">
                  <a-icon type="upload" class="fs-14"></a-icon>上传签名</a-button>
                <a-button type="primary" v-else><a-icon type="upload" class="fs-14"></a-icon>更换签名</a-button>
                <span class="tips line-2em ml10"> 可选择png/jpg/gif等图片,建议尺寸100*100px </span>
              </a-upload>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
      validatorRules: {
        signPath2: [{ required: true, message: '请上传签名图片' }],
      },

使用$set赋值给form的校验文件值:

handleSignUpload(info) {
      this.loading = true;
      if (info.file.status !== 'uploading') {
        console.log(info.file, info.fileList);
      }
      if (info.file.status === 'done') {
        this.loading = false;
        const res = info.file.response;
        if (res.errcode == 0) {
          this.$message.success(res.message || `${info.file.name} 文件上传成功`)

          this.$set(this.model, 'signPath2', res.data.url)//使用$set赋值给form的校验文件值
        } else {
          this.$message.error(`${info.file.name} ${res.errmsg}.`);
        }
      } else if (info.file.status === 'error') {
       
    },
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值