Skip to content

Commit

Permalink
fix(editor): modelValue自动更新不成功
Browse files Browse the repository at this point in the history
  • Loading branch information
roymondchen committed Dec 7, 2022
1 parent 8ab6cdb commit e813129
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/editor/src/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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<MNode | null>('node')?.id || props.defaultSelected;
let node;
if (nodeId) {
Expand All @@ -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);
}
});
Expand Down
3 changes: 2 additions & 1 deletion packages/editor/src/services/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,15 @@ class Editor extends BaseService {
* @param value MNode
*/
public set<T = MNode>(name: keyof StoreState, value: T) {
const preValue = this.state[name];
this.state[name] = value as any;
// set nodes时将node设置为nodes第一个元素
if (name === 'nodes') {
this.set('node', (value as unknown as MNode[])[0]);
}
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);
}
}

Expand Down

0 comments on commit e813129

Please sign in to comment.