Vue3 antdv 简单表单校验

Vue3 antdv 简单表单校验

<template>
  <a-form
    ref="formRef"
    name="custom-validation"
    :model="formState"
    v-bind="layout"
  >
    <a-form-item has-feedback label="aaaaa" name="pass">
      <a-input
        v-model:value="formState.pass"
        type="password"
        autocomplete="off"
      />
    </a-form-item>
    <a-form-item has-feedback label="Confirm" name="checkPass">
      <a-input
        v-model:value="formState.checkPass"
        type="password"
        autocomplete="off"
      />
    </a-form-item>
    <a-form-item has-feedback label="Age" name="age">
      <a-input-number v-model:value="formState.age" />
    </a-form-item>
    <a-form-item :wrapper-col="{ span: 14, offset: 4 }">
      <a-button type="primary" html-type="submit">Submit</a-button>
      <a-button style="margin-left: 10px" @click="resetForm">Reset</a-button>
    </a-form-item>
  </a-form>
</template>
<script>
import { defineComponent, reactive, ref } from "vue";
export default defineComponent({
  setup() {
    const formRef = ref();
    const formState = reactive({
      pass: "",
      checkPass: "",
      age: undefined,
    });

    const layout = {
      labelCol: {
        span: 4,
      },
      wrapperCol: {
        span: 14,
      },
    };

    const resetForm = () => {
      formRef.value.resetFields();
    };

    return {
      formState,
      formRef,
      layout,
      resetForm,
    };
  },
});
</script>

antdv自定义校验规则

上一篇:vue3的新特性


下一篇:1191901-33-3,TCO-NHS Ester,Trans-Cyclooctene-NHS ester,反式环辛烯-活性脂