Commit 35e1347029e29a83a9648b6b398e6863cc40fca9
1 parent
d95815b5
fix(markdown): set `value` error
修复markdown组件在完成初始化之前动态设置value可能导致异常的问题
Showing
1 changed file
with
7 additions
and
8 deletions
src/components/Markdown/src/Markdown.vue
... | ... | @@ -59,8 +59,8 @@ |
59 | 59 | (v) => { |
60 | 60 | if (v !== valueRef.value) { |
61 | 61 | instance.getVditor()?.setValue(v); |
62 | - valueRef.value = v; | |
63 | 62 | } |
63 | + valueRef.value = v; | |
64 | 64 | } |
65 | 65 | ); |
66 | 66 | |
... | ... | @@ -85,7 +85,7 @@ |
85 | 85 | const wrapEl = unref(wrapRef) as HTMLElement; |
86 | 86 | if (!wrapEl) return; |
87 | 87 | const bindValue = { ...attrs, ...props }; |
88 | - vditorRef.value = new Vditor(wrapEl, { | |
88 | + const insEditor = new Vditor(wrapEl, { | |
89 | 89 | theme: getDarkMode.value === 'dark' ? 'dark' : 'classic', |
90 | 90 | lang: unref(getCurrentLang), |
91 | 91 | mode: 'sv', |
... | ... | @@ -100,7 +100,10 @@ |
100 | 100 | after: () => { |
101 | 101 | nextTick(() => { |
102 | 102 | modalFn?.redoModalHeight?.(); |
103 | + insEditor.setValue(valueRef.value); | |
104 | + vditorRef.value = insEditor; | |
103 | 105 | initedRef.value = true; |
106 | + emit('get', instance); | |
104 | 107 | }); |
105 | 108 | }, |
106 | 109 | blur: () => { |
... | ... | @@ -124,14 +127,10 @@ |
124 | 127 | vditorInstance?.destroy?.(); |
125 | 128 | } catch (error) {} |
126 | 129 | vditorRef.value = null; |
130 | + initedRef.value = false; | |
127 | 131 | } |
128 | 132 | |
129 | - onMountedOrActivated(() => { | |
130 | - nextTick(() => { | |
131 | - init(); | |
132 | - }); | |
133 | - emit('get', instance); | |
134 | - }); | |
133 | + onMountedOrActivated(init); | |
135 | 134 | |
136 | 135 | onBeforeUnmount(destroy); |
137 | 136 | onDeactivated(destroy); | ... | ... |