Browse Source

:art: https://github.com/Vanessa219/vditor/issues/1790

Vanessa 5 months ago
parent
commit
0fec6d9033
1 changed files with 8 additions and 3 deletions
  1. 8 3
      src/index.ts

+ 8 - 3
src/index.ts

@@ -41,6 +41,7 @@ import {accessLocalStorage} from "./ts/util/compatibility";
 class Vditor extends VditorMethod {
     public readonly version: string;
     public vditor: IVditor;
+    private isDestroyed = false;
 
     /**
      * @param id 要挂载 Vditor 的元素或者元素 ID。
@@ -58,7 +59,7 @@ class Vditor extends VditorMethod {
                     },
                 };
             } else if (!options.cache) {
-                options.cache = {id: `vditor${id}`};
+                options.cache = { id: `vditor${id}` };
             } else if (!options.cache.id) {
                 options.cache.id = `vditor${id}`;
             }
@@ -101,7 +102,7 @@ class Vditor extends VditorMethod {
     private showErrorTip(error: string) {
         const tip = new Tip();
         document.body.appendChild(tip.element);
-        tip.show(error, 0)
+        tip.show(error, 0);
     }
 
     public updateToolbarConfig(options: IToolbarConfig) {
@@ -369,7 +370,7 @@ class Vditor extends VditorMethod {
         this.vditor.element.innerHTML = this.vditor.originalInnerHTML;
         this.vditor.element.classList.remove("vditor");
         this.vditor.element.removeAttribute("style");
-        const iconScript = document.getElementById("vditorIconScript")
+        const iconScript = document.getElementById("vditorIconScript");
         if (iconScript) {
             iconScript.remove();
         }
@@ -378,6 +379,7 @@ class Vditor extends VditorMethod {
         UIUnbindListener();
         this.vditor.wysiwyg.unbindListener();
         this.vditor.options.after = undefined;
+        this.isDestroyed = true;
     }
 
     /** 获取评论 ID */
@@ -484,6 +486,9 @@ class Vditor extends VditorMethod {
     }
 
     private init(id: HTMLElement, mergedOptions: IOptions) {
+        if (this.isDestroyed) {
+            return;
+        }
         this.vditor = {
             currentMode: mergedOptions.mode,
             element: id,