Vue3组件内容不更新求助:Teleport+Transition+Slot组合异常
问题:AppSidePanel组件嵌套BuildingMaker时状态不更新
我遇到一个问题,AppSidePanel组件无法正确反映传入内容的当前状态。
AppSidePanel组件代码
<template> <teleport :to="`#app-side-panel-container--${side}`"> <transition :name="`slide-fade-${side}`"> <div v-show="showSidePanel" class="app-side-panel" :style="`--header-height: ${header ? '44px' : '0px'}`" > <div v-if="header" class="app-side-panel__header"> <slot name="header"> <span class="app-side-panel__header__title"> {{ title }} </span> <BIMDataButton ghost rounded icon @click="closeSidePanel"> <BIMDataIcon name="close" size="xxs" fill color="granite-light" /> </BIMDataButton> </slot> </div> <div class="app-side-panel__content"> <slot></slot> </div> </div> </transition> </teleport> </template>
组件使用方式
<AppSidePanel> <BuildingMaker :apiClient="apiClient" :space="project.cloud" :project="project" :model="currentModel" @metaBuilding-created="loadProjectModels(project)" @metaBuilding-deleted="loadProjectModels(project)" /> </AppSidePanel>
预期效果与实际问题
- 点击「Créer」打开BuildingMaker组件时,显示组件首页——此功能正常
- 点击「Editer」编辑特定建筑时,显示该建筑的详情页面——此功能异常
实际情况:点击编辑后仍显示BuildingMaker组件的首页!



已验证情况
当用硬编码结构替换AppSidePanel组件时,BuildingMaker组件能正常根据需求显示首页或特定建筑详情:
<transition name="slide-fade-right"> <div v-if="isBMOpen" class="pdf-manager__building-maker"> <div class="pdf-manager__building-maker__header"> <BIMDataButton ghost rounded icon @click="closeBM"> <BIMDataIcon name="close" size="xxs" fill color="granite-light" /> </BIMDataButton> </div> <div class="pdf-manager__building-maker__content"> <BuildingMaker :apiClient="apiClient" :space="project.cloud" :project="project" :model="currentModel" @metaBuilding-created="loadProjectModels(project)" @metaBuilding-deleted="loadProjectModels(project)" /> </div> </div> </transition>
怀疑方向
我怀疑问题出在Teleport、Transition和Slot三者的组合使用上,Vue可能无法很好地处理这种场景,希望得到解决方案建议。
内容的提问来源于stack exchange,提问作者x2cheese
相关产品推荐
相关产品推荐

