diff --git a/runtime/tmagic-form/package.json b/runtime/tmagic-form/package.json index e4665425..4748c825 100644 --- a/runtime/tmagic-form/package.json +++ b/runtime/tmagic-form/package.json @@ -1,5 +1,5 @@ { - "version": "1.1.3", + "version": "1.1.4", "name": "@tmagic/tmagic-form-runtime", "type": "module", "main": "dist/tmagic-form-runtime.umd.cjs", diff --git a/runtime/tmagic-form/src/App.vue b/runtime/tmagic-form/src/App.vue index 293b771c..7155077f 100644 --- a/runtime/tmagic-form/src/App.vue +++ b/runtime/tmagic-form/src/App.vue @@ -12,7 +12,7 @@ import { useFormConfig } from './useFormConfig'; const props = defineProps(); -const { mForm, formConfig, config, values } = useFormConfig(props); +const { formConfig, config, values } = useFormConfig(props); watch(formConfig, async () => { setTimeout(() => { diff --git a/runtime/tmagic-form/src/useFormConfig.ts b/runtime/tmagic-form/src/useFormConfig.ts index c51a541d..353948c2 100644 --- a/runtime/tmagic-form/src/useFormConfig.ts +++ b/runtime/tmagic-form/src/useFormConfig.ts @@ -73,8 +73,15 @@ export const useFormConfig = (props: AppProps) => { return nextTick().then(() => getElById()(document, `${id}`) as HTMLElement); }, - add({ config, parentId }: UpdateData) { - if (!root.value) throw new Error('error'); + add({ config, parentId, root: appConfig }: UpdateData) { + if (!root.value) { + if (appConfig) { + root.value = appConfig; + resetValues(); + return; + } + throw new Error('error'); + } if (!selectedId.value) throw new Error('error'); if (!parentId) throw new Error('error'); @@ -97,8 +104,17 @@ export const useFormConfig = (props: AppProps) => { resetValues(); }, - update({ config, parentId }: UpdateData) { - if (!root.value || !app) throw new Error('error'); + update({ config, parentId, root: appConfig }: UpdateData) { + if (!root.value) { + if (appConfig) { + root.value = appConfig; + resetValues(); + return; + } + throw new Error('error'); + } + + if (!app) throw new Error('error'); const newNode = app.dataSourceManager?.compiledNode(config) || config; replaceChildNode(reactive(newNode), [root.value], parentId);