bill před 1 rokem
rodič
revize
a9dae9ef67
3 změnil soubory, kde provedl 12 přidání a 4 odebrání
  1. 0 1
      src/main.ts
  2. 6 2
      src/model/app.vue
  3. 6 1
      src/model/index.ts

+ 0 - 1
src/main.ts

@@ -15,7 +15,6 @@ app.use(router)
 app.mount('#app')
 
 appStyleImport[params.app]()
-
 watchEffect((onCleanup) => {
   if ([RoutesName.show, RoutesName.signModel].includes(currentLayout.value!)) {
 

+ 6 - 2
src/model/app.vue

@@ -111,7 +111,12 @@ export const Model = defineComponent({
         };
 
         const interval = setInterval(async () => {
-          const doc = iframeRef.value?.contentWindow?.document!
+          let doc: Document | undefined
+          try {
+            doc = iframeRef.value?.contentWindow?.document!
+          } catch {
+            clearInterval(interval);
+          }
           if (!doc || !doc.querySelector("div")) return;
           console.error(doc, doc.head)
           const target = doc.head
@@ -127,7 +132,6 @@ export const Model = defineComponent({
             `);
             $style.appendChild(textNode);
             target.appendChild($style);
-            console.error(target, $style)
           }
         }, 16);
         onCleanup(() => clearInterval(interval));

+ 6 - 1
src/model/index.ts

@@ -56,7 +56,12 @@ const _loadModel = (() => {
 
 
 let isInitial = false
-export const loadModel = (modelType: ModelType): Promise<ModelExpose> => {
+export const loadModel = async (modelType: ModelType): Promise<ModelExpose> => {
+  // 给 vue 加载时间,防止一进入就直接加载模型导致 vue 尚未初始化
+  if (!isInitial) {
+    await new Promise((resolve) => setTimeout(resolve, 10));
+  }
+
   const modelPromise = _loadModel(modelType)
   if (!isInitial) {
     if (!appEl.value) {