Browse Source

:bug: 参数为空时异常

Liyuan Li 5 years ago
parent
commit
8486bd50ea
2 changed files with 8 additions and 4 deletions
  1. 7 3
      src/index.ts
  2. 1 1
      types/index.d.ts

+ 7 - 3
src/index.ts

@@ -51,10 +51,14 @@ class Vditor extends VditorMethod {
         this.version = VDITOR_VERSION;
 
         if (typeof id === "string") {
-            if (!options.cache) {
-                options.cache = {
-                    id: `vditor${id}`,
+            if (!options) {
+                options = {
+                    cache: {
+                        id: `vditor${id}`,
+                    },
                 };
+            } else if (!options.cache) {
+                options.cache = {id: `vditor${id}`};
             } else if (!options.cache.id) {
                 options.cache.id = `vditor${id}`;
             }

+ 1 - 1
types/index.d.ts

@@ -449,7 +449,7 @@ interface IOptions {
     /** @link https://hacpai.com/article/1549638745630#options-hint */
     hint?: IHint;
     /** @link https://hacpai.com/article/1549638745630#options-toolbarConfig */
-    toolbarConfig: {
+    toolbarConfig?: {
         hide?: boolean,
         pin?: boolean,
     };