DEV Community

ChuangWANG
ChuangWANG

Posted on

Element-UI

ElementUI rules format

note: the rules should in data() {}

data () {
  return {
    rules: {
        productKey: { required: true, message: '请选择产品', trigger: 'change' },
        // errorCode: { required: true, message: '请填写故障代码', trigger: ['change', 'blur'] },
        errorNum: { required: true, message: '请填写故障位', trigger: ['change', 'blur'] },
        errorDesc: { required: true, message: '请填写故障详情', trigger: ['change', 'blur'] }
      },
  }
}
Enter fullscreen mode Exit fullscreen mode

Form validate trigger by event

methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)