fix(use-safe-n-form): 更改 formRef 为 formInst
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const { formValue, SafeNForm, SafeNFormItem, formRef } = useSafeNForm({
|
const { formInst, formValue, SafeNForm, SafeNFormItem } = useSafeNForm({
|
||||||
initialFormValue: {
|
initialFormValue: {
|
||||||
/* ⚠️:
|
/* ⚠️:
|
||||||
如果没使用`SafeNFormItem`,
|
如果没使用`SafeNFormItem`,
|
||||||
@@ -15,7 +15,7 @@ const { formValue, SafeNForm, SafeNFormItem, formRef } = useSafeNForm({
|
|||||||
});
|
});
|
||||||
|
|
||||||
function handleValidateClick() {
|
function handleValidateClick() {
|
||||||
formRef.value?.validate((errors) => {
|
formInst.value?.validate((errors) => {
|
||||||
if (!errors) {
|
if (!errors) {
|
||||||
window.$nMessage!.success('Valid');
|
window.$nMessage!.success('Valid');
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ type UseSafeNFormOptions<FormValue> = {
|
|||||||
export function useSafeNForm<T extends Record<string, any> = Record<string, unknown>>(
|
export function useSafeNForm<T extends Record<string, any> = Record<string, unknown>>(
|
||||||
options: UseSafeNFormOptions<T> = {},
|
options: UseSafeNFormOptions<T> = {},
|
||||||
) {
|
) {
|
||||||
const formRef = ref<FormInst | null>(null);
|
const formInst = ref<FormInst | null>(null);
|
||||||
const formValue = ref<T>(structuredClone(toRaw(options.initialFormValue)) || ({} as T));
|
const formValue = ref<T>(structuredClone(toRaw(options.initialFormValue)) || ({} as T));
|
||||||
|
|
||||||
// 创建类型安全的 Form 组件
|
// 创建类型安全的 Form 组件
|
||||||
@@ -35,7 +35,7 @@ export function useSafeNForm<T extends Record<string, any> = Record<string, unkn
|
|||||||
{...props}
|
{...props}
|
||||||
model={formValue.value}
|
model={formValue.value}
|
||||||
ref={(inst) => {
|
ref={(inst) => {
|
||||||
formRef.value = inst as unknown as FormInst;
|
formInst.value = inst as unknown as FormInst;
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{ctx.slots.default?.({})}
|
{ctx.slots.default?.({})}
|
||||||
@@ -116,6 +116,6 @@ export function useSafeNForm<T extends Record<string, any> = Record<string, unkn
|
|||||||
formValue,
|
formValue,
|
||||||
SafeNForm,
|
SafeNForm,
|
||||||
SafeNFormItem,
|
SafeNFormItem,
|
||||||
formRef,
|
formInst,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user