Skip to content

[Question] Help 有没有遇到过pro-layout 默认插槽中使用RouterView,而RouterView再使用插槽渲染当前页面对应组件,组件会渲染两次的情况? #251

Open
@YTT-TTY

Description

@YTT-TTY

🧐 问题描述 Problem Description

有没有遇到过pro-layout 默认插槽中使用RouterView,而RouterView再使用插槽渲染当前页面对应组件,组件会渲染两次的情况?

💻 示例代码 Sample code

const BasicLayout = defineComponent({
setup(props, { slots }) {
const multiTabState = useMultiTabStateProvider();
const { layoutConfig, locale, collapsed, selectedKeys, openKeys, menuData, breadcrumb, sideWidth } = useMenuState(multiTabState);

    const breadcrumbRender = ({ route, params, routes }: Breadcrumb) => (
        routes.indexOf(route) === routes.length - 1 ? <span> {route.breadcrumbName}</span>
            : <RouterLink to={{ path: route.path, params }}>{route.breadcrumbName}</RouterLink>
    )

    return () => (
        <ProLayout
            logo={`${process.env.VUE_APP_PUBLIC_PATH}logo.png`}
            locale={locale}
            {...layoutConfig}
            menuData={menuData}
            v-models={[
                [collapsed.value, 'collapsed'],
                [selectedKeys.value, 'selectedKeys'],
                [openKeys.value, 'openKeys'],
            ]}
            breadcrumb={{ routes: breadcrumb.value }}
            v-slots={{
                default: () => <>
                    {SettingConfig.multiTab && <MultiTab fixed={SettingConfig.multiTabFixed} />}

                    <div class={[{ 'ant-layout-content-has-multiTab': SettingConfig.multiTab }]}>
                        <RouterView
                            // TODO优化:会渲染两次
                            v-slots={{
                                default: ({ Component, route }: RouterViewSlot) => (

                                    h(Component)

                                )
                            }}
                        />
                    </div>

                </>,
                breadcrumbRender: ({ route, params, routes }: Breadcrumb) => breadcrumbRender({ route, params, routes }),
                rightContentRender: () => <RightContent />
            }}
        />
    )
}

});

🚑 其他信息 Other information

组件对应代码以及浏览器打印渲染信息

code
页面

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions