From 76cae465069745a9f1b7924d748988f69bd93d7d Mon Sep 17 00:00:00 2001 From: Warren Kole <41220285+xs-sun@users.noreply.github.com> Date: Wed, 13 Mar 2024 15:46:51 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3setHtml=E6=97=B6editor?= =?UTF-8?q?=E8=BF=98=E6=9C=AA=E5=88=9B=E5=BB=BA=E5=AF=BC=E8=87=B4=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=99=A8=E4=B8=8D=E6=98=BE=E7=A4=BA=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Editor.vue | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/Editor.vue b/src/components/Editor.vue index 350b825..654d95b 100644 --- a/src/components/Editor.vue +++ b/src/components/Editor.vue @@ -18,6 +18,7 @@ export default Vue.extend({ return { curValue: '', editor: null, + handles: [] }; }, props: ['defaultContent', 'defaultConfig', 'mode', 'defaultHtml', 'value'], // value 用于自定义 v-model @@ -38,7 +39,12 @@ export default Vue.extend({ // 重置 HTML setHtml(newHtml: string) { const editor = this.editor as any; - if (editor == null) return; + if (editor == null) { + this.handles.push(() => { + this.setHtml(newHtml); + }) + return + }; editor.setHtml(newHtml); }, @@ -59,7 +65,11 @@ export default Vue.extend({ ...defaultConfig, onCreated: (editor) => { this.editor = Object.seal(editor) as any; // 注意,一定要用 Object.seal() 否则会报错 - + // 解决setHtml时 editor还未创建的bug + while (this.handles.length > 0) { + const handle = this.handles.pop() + handle(); + } this.$emit('onCreated', editor); if (defaultConfig.onCreated) { const info = genErrorInfo('onCreated');