Skip to content

Commit 9763ccb

Browse files
committed
fix: should not change preventUpdatingModelValue when jsonEditor.value is empty
1 parent 2071495 commit 9763ccb

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/Component.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,17 @@ export default defineComponent({
125125
preventUpdatingContent.value = false
126126
return
127127
}
128-
preventUpdatingModelValue.value = true
129-
// `jsonEditor.value` could be `undefined` in Vue 2.6 (dev environment)
130-
jsonEditor.value?.set(
131-
[undefined, ''].includes(newModelValue)
132-
// `undefined` is not accepted by vanilla-jsoneditor
133-
// The default value is `{ text: '' }`
134-
// Only default value can clear the editor
135-
? { text: '' }
136-
: { json: newModelValue },
137-
)
128+
if (jsonEditor.value) {
129+
preventUpdatingModelValue.value = true
130+
jsonEditor.value.set(
131+
[undefined, ''].includes(newModelValue)
132+
// `undefined` is not accepted by vanilla-jsoneditor
133+
// The default value is `{ text: '' }`
134+
// Only default value can clear the editor
135+
? { text: '' }
136+
: { json: newModelValue },
137+
)
138+
}
138139
},
139140
{
140141
deep: true,

0 commit comments

Comments
 (0)