element-ui中的el-form表单验证,只有在提交按钮点击时才进行验证

element-ui中的el-form表单验证,只有在提交按钮点击时才进行验证,这样会减少消耗。看别人写的文章 ,只有在写怎么添加验证,不能满足我的需求。
其实很简单,直接在el-input上加一个属性就行,

<el-input
  ref="nodeName"
  v-model="form.nodeName"
  maxlength="122"
  show-word-limit
  :validate-event="false" />  // 就是 本行所在的位置 
rules: {
        nodeName: [
          { required: true, message: '请输入名称' },'blur'去掉,是鼠标失去焦点的时候会触发验证
        ],
      },
**在点击确定按钮的时候,触发函数,然后进行验证**
handleConfirm () {
      this.$refs.form.validate((valid) => {
        if (valid) {
         // 向后台发送请求
        } else {
          //就像用户提示发生错误的消息
        }
      })
    },
发布了24 篇原创文章 · 获赞 2 · 访问量 9177

猜你喜欢

转载自blog.csdn.net/sunmeng_sunmeng/article/details/103893823