@@ -10,8 +10,9 @@ const container = ref<HTMLDivElement | null>(null)
1010const view = ref <EditorView >()
1111const state = ref <EditorState >()
1212
13- const props = withDefaults (defineProps <NuxtCodeMirrorProps >(), {
14- modelValue: ' ' ,
13+ const modelValue = defineModel <string >({ default: ' ' })
14+
15+ const props = withDefaults (defineProps <Omit <NuxtCodeMirrorProps , ' modelValue' >>(), {
1516 extensions : () => [],
1617 theme: ' light' ,
1718})
@@ -35,7 +36,11 @@ onMounted(async () => {
3536
3637 useNuxtCodeMirror ({
3738 ... props ,
38- onChange : (value , viewUpdate ) => emit (' onChange' , value , viewUpdate ),
39+ modelValue: modelValue .value ,
40+ onChange : (value , viewUpdate ) => {
41+ modelValue .value = value
42+ emit (' onChange' , value , viewUpdate )
43+ },
3944 onStatistics : data => emit (' onStatistics' , data ),
4045 onCreateEditor : (view , state ) => emit (' onCreateEditor' , { view , state }),
4146 onUpdate : viewUpdate => emit (' onUpdate' , viewUpdate ),
@@ -52,7 +57,7 @@ onMounted(async () => {
5257 // console.log('test: ', view.value)
5358})
5459
55- watch (() => props . modelValue , (newValue ) => {
60+ watch (() => modelValue , (newValue ) => {
5661 if (typeof newValue !== ' string' ) {
5762 console .error (` value must be typeof string but got ${typeof newValue } ` )
5863 }
0 commit comments