fix: del cur page still request current page again caught error (#1432)
This commit is contained in:
parent
0d35f481ae
commit
8b91cf12ce
|
|
@ -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<string, any> = {}
|
|||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue