Skip to content

Commit

Permalink
fix(markdown): set value error
Browse files Browse the repository at this point in the history
修复markdown组件在完成初始化之前动态设置value可能导致异常的问题
  • Loading branch information
mynetfan committed Jul 13, 2021
1 parent d95815b commit 35e1347
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/components/Markdown/src/Markdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
(v) => {
if (v !== valueRef.value) {
instance.getVditor()?.setValue(v);
valueRef.value = v;
}
valueRef.value = v;
}
);
Expand All @@ -85,7 +85,7 @@
const wrapEl = unref(wrapRef) as HTMLElement;
if (!wrapEl) return;
const bindValue = { ...attrs, ...props };
vditorRef.value = new Vditor(wrapEl, {
const insEditor = new Vditor(wrapEl, {
theme: getDarkMode.value === 'dark' ? 'dark' : 'classic',
lang: unref(getCurrentLang),
mode: 'sv',
Expand All @@ -100,7 +100,10 @@
after: () => {
nextTick(() => {
modalFn?.redoModalHeight?.();
insEditor.setValue(valueRef.value);
vditorRef.value = insEditor;
initedRef.value = true;
emit('get', instance);
});
},
blur: () => {
Expand All @@ -124,14 +127,10 @@
vditorInstance?.destroy?.();
} catch (error) {}
vditorRef.value = null;
initedRef.value = false;
}
onMountedOrActivated(() => {
nextTick(() => {
init();
});
emit('get', instance);
});
onMountedOrActivated(init);
onBeforeUnmount(destroy);
onDeactivated(destroy);
Expand Down

0 comments on commit 35e1347

Please sign in to comment.