From e813129eb8ea6e11e683c081847dd17fb1104dfd Mon Sep 17 00:00:00 2001 From: roymondchen Date: Wed, 7 Dec 2022 16:26:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(editor):=20modelValue=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=B8=8D=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/editor/src/Editor.vue | 4 ++-- packages/editor/src/services/editor.ts | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/editor/src/Editor.vue b/packages/editor/src/Editor.vue index 96dba8c27..b0cf2ad18 100644 --- a/packages/editor/src/Editor.vue +++ b/packages/editor/src/Editor.vue @@ -223,7 +223,7 @@ export default defineComponent({ emits: ['props-panel-mounted', 'update:modelValue'], setup(props, { emit }) { - editorService.on('root-change', (value) => { + editorService.on('root-change', (value, preValue) => { const nodeId = editorService.get('node')?.id || props.defaultSelected; let node; if (nodeId) { @@ -240,7 +240,7 @@ export default defineComponent({ editorService.set('page', null); } - if (toRaw(value) !== toRaw(editorService.get('root'))) { + if (toRaw(value) !== toRaw(preValue)) { emit('update:modelValue', value); } }); diff --git a/packages/editor/src/services/editor.ts b/packages/editor/src/services/editor.ts index 2f1d3e714..356a438c4 100644 --- a/packages/editor/src/services/editor.ts +++ b/packages/editor/src/services/editor.ts @@ -95,6 +95,7 @@ class Editor extends BaseService { * @param value MNode */ public set(name: keyof StoreState, value: T) { + const preValue = this.state[name]; this.state[name] = value as any; // set nodes时将node设置为nodes第一个元素 if (name === 'nodes') { @@ -102,7 +103,7 @@ class Editor extends BaseService { } if (name === 'root') { this.state.pageLength = (value as unknown as MApp)?.items?.length || 0; - this.emit('root-change', value); + this.emit('root-change', value, preValue); } }