|
19 | 19 | ></tiny-input> |
20 | 20 | </tiny-form-item> |
21 | 21 | <tiny-form-item class="demo-form-validate-item"> |
22 | | - <tiny-button type="primary" @click="handleSubmit('ruleForm')">提交</tiny-button> |
23 | | - <tiny-button type="primary" @click="clearValidate('ruleForm')">移除校验</tiny-button> |
24 | | - <tiny-button type="primary" @click="resetFields('ruleForm')">重置</tiny-button> |
| 22 | + <tiny-button type="primary" @click="handleSubmit">提交</tiny-button> |
| 23 | + <tiny-button type="primary" @click="clearValidate">移除校验</tiny-button> |
| 24 | + <tiny-button type="primary" @click="resetFields">重置</tiny-button> |
25 | 25 | </tiny-form-item> |
26 | 26 | </tiny-form> |
27 | 27 | </div> |
@@ -63,25 +63,23 @@ const createData = ref({ |
63 | 63 | users: '', |
64 | 64 | user: '' |
65 | 65 | }) |
| 66 | +const ruleFormRef = ref(null) |
66 | 67 | const rules = ref({ |
67 | 68 | users: [{ required: true, message: '必填', trigger: 'change' }] |
68 | 69 | }) |
69 | 70 | const boxVisibility = ref(false) |
70 | 71 | const formNameRef = ref() |
71 | 72 |
|
72 | | -function clearValidate(formName) { |
73 | | - // FIXIME $refs自动转换失败,请手工修改 |
74 | | -$refs[formName].clearValidate() |
| 73 | +function clearValidate() { |
| 74 | +ruleFormRef.value.clearValidate() |
75 | 75 | } |
76 | 76 |
|
77 | | -function resetFields(formName) { |
78 | | - // FIXIME $refs自动转换失败,请手工修改 |
79 | | -$refs[formName].resetFields() |
| 77 | +function resetFields() { |
| 78 | +ruleFormRef.value.resetFields() |
80 | 79 | } |
81 | 80 |
|
82 | | -function handleSubmit(formName) { |
83 | | - // FIXIME $refs自动转换失败,请手工修改 |
84 | | -$refs[formName].validate((valid) => { |
| 81 | +function handleSubmit() { |
| 82 | +ruleFormRef.value.validate((valid) => { |
85 | 83 | if (valid) { |
86 | 84 | boxVisibility.value = true |
87 | 85 | } |
|
0 commit comments