elementUI 非表单格式的校验

 在普通表单中对输入框、选择框都有校验案例。

但是在自定义非空中如何进行校验官网并没有说明

关键代码 clearValidate 方法清除校验

 this.$refs.formValue.clearValidate('signinimg')

使用案例

<template>
    <div class="stylebg">
      <Tabs icons="el-icon-shopping-bag-2" :arrs="tabs" />
     
     
      <!--表格  -->
      <div style="margin-top: 20px">
        <el-form ref="formValue"  label-width="120px" :rules="rules" :model="formValue">
            <el-form-item label="标题" prop="title">
              <el-input v-model="formValue.title" placeholder="请输入标题"></el-input>
            </el-form-item>
             
            
            <el-form-item label="单选图">
              <div class="imagelist">
                  <div class="imagelist imgbox" @click="uploadimg('img','1')" v-if="formValue.img">
                      <el-image class="img" :src="formValue.img" fit="cover" ></el-image>
                  </div>  
                  <div  style="border: 1px dashed #d9d9d9;" class="avatar-uploader"   @click="uploadimg('img','1')" v-else>
                      <i class="el-icon-plus" style="width: 100px;height: 100px;display: flex;align-items: center;justify-content: center;"></i>
                </div>
              </div>
            </el-form-item>
            <el-form-item label="多选图">
              <div class="imagelist">
                  <div v-for="(item, i) in formValue.imgs" :key="i" class="imagelist imgbox">
                      <el-image class="img" :src="item" fit="cover" ></el-image>
                      <img src="@/assets/close.png" class="close" @click="handleRemove(i)"/>
                  </div>  
                  <div  style="border: 1px dashed #d9d9d9;" class="avatar-uploader"   @click="uploadimg('imgs','2')">
                      <i class="el-icon-plus" style="width: 100px;height: 100px;display: flex;align-items: center;justify-content: center;"></i>
                </div>
              </div>
            </el-form-item>
            <el-form-item label="电子签名" prop="signinimg">
              <div  @click="signinVisible=true" style="width: 200px;background-color: #d9d9d9;">
                <el-image :src="formValue.signinimg" style="width: 200px;height: 100px;display: flex;align-items: center;justify-content: center;color: #999;">
                  <div slot="error" > 点击签名 </div>
                </el-image>
              </div>
            </el-form-item>
            <el-form-item label="">
              <el-button type="primary" size="small"  @click="upform">确定</el-button>
              <el-button type="primary" size="small"  @click.native="back">返回</el-button>
            </el-form-item>
        </el-form>
        
       
      </div>
      <el-dialog title="选择图片" :visible.sync="dialogVisible" width="900px">
        <uploadDialog  v-if="dialogVisible" @getPic="getPic" :chosetype="picChoseType"></uploadDialog>
      </el-dialog>

      <el-dialog title="电子签名" :visible.sync="signinVisible" width="700px">
       
          <signinDia @setsignin="setsignin"></signinDia>
        
      </el-dialog>


    </div>
  </template>
  
  <script>
 import wueditor from '@/components/wueditor.vue'; // ES6 Module
 import {addcaseAPI,getcaseinfoAPI,updatecaseAPI} from "@/api/article"
 import uploadDialog from "@/components/uploadDialog.vue"
 import signinDia from "@/components/signinDia.vue"
  export default {
    components: {
      wueditor,uploadDialog,signinDia
    },
    data() {
      return {
        formValue:{
          img:"",
          imgs:[],
          status:0
        },
       
        headers:{},
        tabs: ["轮播图管理", "添加轮播图"],
        dynamicTags: [],
        dialogVisible: false,
        signinVisible: false,
      
        inputValue: '',
       

        picTit:"",
        picChoseType:"1",
        rules:{
          title: [ { required: true, message: '名称不能为空', change: 'blur', }],
          signinimg: [ { required: true, message: '电子签名不能为空'  }],
        }
      };
    },
    created() {
      this.headers={
        Authorization:"Bearer " +localStorage.getItem('token')
      }
      this.getinfo()
      
    },
    methods: {
      upform(){
        this.$refs.formValue.validate((valid) => {
          if (valid) {
            alert("success")
          }else{
            if(this.formValue.signinimg) this.$refs.formValue.clearValidate('signinimg')
          }
        })
       
        // if (this.$route.query.id) {
        //   updatecaseAPI(this.formValue).then(res=>{
        //     this.$message.success("成功")
        //     this.$router.back()
        //   })    
        //   return
        // }
        // addcaseAPI(this.formValue).then(res=>{
        //   this.$message.success("成功")
        //   this.$router.back()
        // })    
         
      },
      setsignin(img){
        this.formValue.signinimg=img
        this.signinVisible=false
        this.$refs.formValue.clearValidate('signinimg')
      },
      uploadimg(picTit,picChoseType){
        this.dialogVisible=true
        this.picTit=picTit
        this.picChoseType=picChoseType
      },
      getPic(images){
        console.log(images)
        switch(this.picTit){
          case "img":
            this.formValue.img=images.url
          break
          case "imgs":
            var list=this.formValue.imgs

            this.formValue.imgs=list.concat(images.map(item=> item.url))
          break
        }
        this.dialogVisible=false
      },
      handleRemove(i) {
          this.formValue.imgs.splice(i,1) 
      },










      handleClose(tag) {
        this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);
      },

      showInput() {
        this.inputVisible = true;
        this.$nextTick(_ => {
          this.$refs.saveTagInput.$refs.input.focus();
        });
      },

      handleInputConfirm() {
        let inputValue = this.inputValue;
        if (inputValue) {
          this.dynamicTags.push(inputValue);
        }
        this.inputVisible = false;
        this.inputValue = '';
      },
      getinfo(){
        var id=this.$route.query.id
        if (id) {
          getcaseinfoAPI({id}).then(res=>{
            this.formValue=res
            
          })
        }
        
      },
      handleAvatarSuccess2(res){
        this.formValue.img = res.data  
        console.log(res.data  )
      },
   
      back(){
        this.$router.back()
      },
    
  }
  };
  </script>
  
  <style  lang="less">
  .el-tag + .el-tag {
    margin-left: 10px;
  }
  .button-new-tag {
    margin-left: 10px;
    height: 32px;
    line-height: 30px;
    padding-top: 0;
    padding-bottom: 0;
  }
  .input-new-tag {
    width: 90px;
    margin-left: 10px;
    vertical-align: bottom;
  }
  .form {
    margin: 15px 0;
  }
  .page {
    background-color: #fff;
    padding: 10px;
    .el-pagination .btn-next,
    .el-pagination .btn-prev {
      background-color: #ffffff !important;
    }
  }
  .imagelist{
  display: flex;
  align-items: center;
  .imgbox{    
    border: 1px solid #d9d9d9;
    position: relative;
    margin-right: 20px;
    .img{
      width: 100px;
      height: 100px;
      border-radius: 6px;
    }
    .close{
      width: 20px;
      height: 20px;
      position: absolute;
      top: -10px;
      right: -10px;
      cursor: pointer;
    }
  }
}
  </style>
  

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/38328.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

.net6中WPF的串口通信和USB通信

之前写过串口通信&#xff0c;不过是winform的。 c#使用串口进行通信_c# 串口通信_故里2130的博客-CSDN博客 今天说一下&#xff0c;.net6中wpf的串口通信和USB通信&#xff0c;在工控行业中&#xff0c;这2种的方式非常多&#xff0c;还有网口通信&#xff0c;它们都是用来和…

利用ChatGPT场景化学习英语听说读写

大家好&#xff0c;我是可夫小子&#xff0c;关注AIGC、读书和自媒体。解锁更多ChatGPT、AI绘画玩法。加我&#xff0c;备注&#xff1a;chatgpt&#xff0c;拉你进群。 我们从初中就开始学习英语&#xff0c;到大学也有小十年&#xff0c;在这个过程中&#xff0c;我们投入了很…

提高驾驶安全性 | 基于ACM32 MCU的胎压监测仪方案

概述 作为车辆的基础部件&#xff0c;轮胎是影响行车安全不可忽视的因素之一。据统计&#xff0c;中国每年由胎压问题引起轮胎爆炸的交通事故约占 30%&#xff0c;其中 50%的高速交通事故是由车辆胎压异常引起。因此&#xff0c;准确实时地监测车辆在行驶过程中的轮胎压监测系…

Java List中通过对象属性排序,可实现多条件排序

直接上代码&#xff1a; import com.google.common.collect.Lists; import lombok.AllArgsConstructor; import lombok.Data;import java.util.Comparator; import java.util.List; import java.util.stream.Collectors;/*** List 对象属性排序*/Data AllArgsConstructor clas…

【Linux】进程概念

【Linux】进程概念 文章目录 【Linux】进程概念1、冯诺依曼体系结构2、操作系统2.1 概念2.2 设计OS的目的2.3 定位2.4 管理2.5 系统调用和库函数概念 3、进程3.1 基本概念3.2 描述进程—PCB3.3 组织进程3.4 查看进程3.5 获取进程标示符3.6 创建进程-fork初识3.7 进程状态3.7.1 …

Vue2 ➔ Vue3 都做了哪些改变?

不是吧&#xff0c;兄弟&#xff0c;Vue3 都出来多久了&#xff0c;你还对这个感兴趣&#xff0c;说&#xff01;是不是没好好卷&#xff1f;&#x1f60f; 俺也一样 &#x1f602;&#xff0c;Vue3 出来之后只是简单了解了一下&#xff0c;然后还是转头一直在写 Vue2。当然&a…

IIC的再认识

IIC介绍 关于IIC的基本概念&#xff0c;其实在学习89C52的时候已经大致了解过了&#xff0c;且由于STM32支持了IIC协议&#xff0c;所以在STM32中使用IIC可以直接调用HAL库的库函数&#xff1a; HAL_StatusTypeDef HAL_I2C_Mem_Write(I2C_HandleTypeDef *hi2c,uint16_t DevAdd…

IP基础知识总结

IP他负责的是把IP数据包在不同网络间传送&#xff0c;这是网络设计相关的&#xff0c;与操作系统没有关系。所以这部分知识&#xff0c;不是网络的重点。IP和路由交换技术联系紧密。但是要作为基本知识点记住。 一、基本概念 网络层作用&#xff1a;实现主机与主机之间通信。 …

瀚高企业版数据库V6单机安装指导手册(Linux)

目录 瀚高企业版数据库V6单机安装指导手册&#xff08;Linux&#xff09; 1. 环境准备 1.1 防火墙设置 1.1.1 开放数据库使用端口 1.1.2 关闭防火墙 1.2 检查时区和时间 1.3 创建highgo用户 1.4 检验安装包 2. 软件安装 2.1 图形化安装 3. 设置highgo用户环境变量 4.…

mysql 1 -- 数据库介绍、mysql 安装及设置

Linux 安装 mysql 1、数据库&#xff08;mysql&#xff09; 数据文件 - 数据库过了系统 2、c/s mysql 服务器 mysql 客户端 ip port : 3306 3、关系型 于 非关系型数据库&#xff08;nosql&#xff09; nosql可以解决一些关系型数据库所无法实现的场景引用。 一、数据库介绍 …

计算机网络——三次握⼿、四次挥手

TCP 三次握手 1、第⼀个SYN报⽂&#xff1a; 客户端随机初始化序列号client_isn&#xff0c;放进TCP⾸部序列号段&#xff0c; 然后把SYN置1。把SYN报⽂发送给服务端&#xff0c;表⽰发起连接&#xff0c; 之后客户端处于SYN-SENT状态。 2、第⼆个报⽂SYNACK报⽂&#xff1a; …

郑州网站域名升级https通配符证书

新创建的网站如果没有安装SSL证书&#xff0c;在客户端与服务器传输信息时会使用明文传输&#xff0c;明文传输的数据容易被其他人截获或者插入违法信息&#xff0c;会对网站所有者和访问网站的客户带来危害。而部署了SSL证书将网站域名由http升级为https&#xff0c;会在客户端…

卷积神经网络(CNN)原理详解

近些年人工智能发展迅速&#xff0c;在图像识别、语音识别、物体识别等各种场景上深度学习取得了巨大的成功&#xff0c;例如AlphaGo击败世界围棋冠军&#xff0c;iPhone X内置了人脸识别解锁功能等等&#xff0c;很多AI产品在世界上引起了很大的轰动。 而其中 卷积神经网络&am…

G1垃圾收集器-JVM(十三)

上篇文章说了CMS垃圾收集器使用以及三色标记如何解决cms的一些问题。分别有初始标记&#xff0c;并发标记&#xff0c;重新标记&#xff0c;并发清理&#xff0c;并发重置。 CMS垃圾收集器&三色标记-JVM&#xff08;十二&#xff09; G1收集器&#xff08;Garbage-First&a…

macOS 14 Sonama - 小记

文章目录 Sonoma 官方资讯关于 Sonama 命名关于 壁纸Sonoma 官方资讯 macOS Sonoma Preview https://www.apple.com/hk/en/macos/sonoma-preview/官方视频介绍 Apple Events --> Watch the Keynote --> 00:43:13 (约14min) https://www.apple.com/hk/en/apple-events/mac…

防抖、节流、深拷贝事件总线

1 认识防抖和节流 2 underscore使用 3 防抖函数实现优化 4 节流函数实现优化 5 深拷贝函数的实现 6 事件总线工具实现 简而言之&#xff0c;防抖就是一直触发事件就一直往后拖延再执行。 节流就是一段时间就执行一次&#xff0c;不管中间你触发多少次。 防抖-认识防抖操作…

基于 NNCF 和 Optimum 面向 Intel CPU 对 Stable Diffusion 优化

基于隐空间的扩散模型 (Latent Diffusion Model)&#xff0c;是解决文本到图片生成问题上的颠覆者。Stable Diffusion 是最著名的一例&#xff0c;广泛应用在商业和工业。Stable Diffusion 的想法简单且有效: 从噪声向量开始&#xff0c;多次去噪&#xff0c;以使之在隐空间里逼…

微信加粉计数器后台开发

后台包括管理后台与代理后台两部分 管理后台 管理后台自带网络验证卡密系统,一个后台可以完成对Pc端的全部对接,可以自定义修改分组名称 分享等等代理后台 分享页 调用示例 <?php$request new HttpRequest(); $request->setUrl(http://xxxxxxx/api); $request->…

实现二分搜索函数,设计脚手架程序进行自动测试。

1. 设计思路   二分搜索算法每次将数组中间值与目标值相比较&#xff0c;若相同&#xff0c;则该元素就是要寻找的元素&#xff0c;若不相同&#xff0c;二分搜索法通过一定的方法抛弃一半的待搜索区间&#xff0c;在剩余的区间中继续以相同方法搜索目标值. 2.源代码 #incl…

【数据网格架构】数据网格架构详解

“我想指出&#xff0c;所提供的链接都不是附属的&#xff0c;我从本文中提到的公司中没有任何收获。我做这一切是因为直到最近我才听说过数据网格&#xff0c;我很期待这次活动&#xff0c;并希望在此之前深入了解一下。我还认为这可能会让其他人感兴趣&#xff0c;并付出了额…
最新文章