From 8b91cf12ce5084e6ffbdc36cb412ecf9fef07a51 Mon Sep 17 00:00:00 2001 From: chilingling <26962197+chilingling@users.noreply.github.com> Date: Wed, 28 May 2025 11:15:24 +0800 Subject: [PATCH] fix: del cur page still request current page again caught error (#1432) --- .../src/material-function/page-getter.ts | 31 ++++++------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/packages/canvas/render/src/material-function/page-getter.ts b/packages/canvas/render/src/material-function/page-getter.ts index 520b577a..217802d8 100644 --- a/packages/canvas/render/src/material-function/page-getter.ts +++ b/packages/canvas/render/src/material-function/page-getter.ts @@ -1,4 +1,4 @@ -import { defineComponent, h, onUnmounted, ref, watch } from 'vue' +import { defineComponent, h, ref, onMounted } from 'vue' import { getController } from '../canvas-function' import RenderMain from '../RenderMain' import { handleScopedCss } from './handle-scoped-css' @@ -8,7 +8,7 @@ const pageSchema: Record = {} async function fetchPageSchema(pageId: string) { return getController() .getPageById(pageId) - .then((res) => { + .then((res: any) => { return res.page_content }) } @@ -40,31 +40,20 @@ export const wrapPageComponent = (pageId: string) => { name: `page-${pageId}`, setup() { const active = ref(pageId === getController().getBaseInfo().pageId) - const stop = getController().addHistoryDataChangedCallback(() => { - const newValue = pageId === getController().getBaseInfo().pageId - if (active.value !== newValue) { - active.value = newValue - } - }) - const watchStop = watch( - () => active.value, - (activeValue) => { - if (!activeValue) { - asyncData.value = null - updateSchema() - } - } - ) - onUnmounted(() => { - stop() - watchStop() + + onMounted(() => { + // 切换页面会重新渲染进来,重新渲染说明可能是切换页面了 + // 切换页面后,可能原页面的 schema 更新了,但是我们这里是根据 pageId 获取的 schema, + // 且是在闭包获取的 schema,不会得到更新的 schema + // 所以需要重新获取下 schema,不然可能会造成页面数据未更新 + updateSchema() }) return () => { if (active.value || asyncData.value) { return h(RenderMain, { cssScopeId: key, - renderSchema: asyncData.value, + renderSchema: asyncData.value as any, active: active.value, pageId: pageId, entry: false