12451 b553c4e519 feat: API 统一 + 设备详情补全 + H5 导航优化
- API 路由统一: 移除 /api/h5/,统一 /api/pms/ 入口
- 二进制改名: api-server -> pms-api(与服务名一致)
- nginx: 合并 /api/ + /pms/api/ 为 /api/pms/
- 新增 docs/API.md 接口文档
- 后端: CabinetDetail 增加 rssi/pow_fail/address/soc 等字段
- Redis 管道批量读取仓体实时数据(SOC/电压/电流/功率)
- DB: 所有 TIMESTAMP 列改为 DATETIME(修复类型不匹配)
- 用户管理: 新增创建时间/修改时间列,状态改用 Switch
- 角色管理/用户管理: 操作按钮改为图标
- PC 设备详情: 基本信息补全 RSSI/ICCID/电源/地址
- PC 卡片: 通道统计改用 Lucide 图标,颜色统一
- PC 二维码: canvas 渲染,含编号文字,支持右键下载
- H5: 按 uni-app 规范修正导航(navigateTo 替代 reLaunch)
- H5: 详情页加返回导航条
- H5: 扫码支持摄像头(jsQR)+ ?id= 参数
- H5: 底部 tabBar 在所有页面常显
- H5: 首页统计改为 6 项(设备/通道/空闲/充电/充满/故障)
- H5: 下拉刷新 / 上拉加载
- 产品首页: 添加业务联系
- 文档: 清理过时文件,补充缺失规范章节
2026-07-04 04:03:02 +08:00

3.8 KiB

title, impact, impactDescription, type, tags
title impact impactDescription type tags
Scoped Styles May Not Apply to Teleported Content MEDIUM Scoped styles can fail to apply to teleported elements due to data attribute limitations gotcha
vue3
teleport
scoped-styles
css

Scoped Styles May Not Apply to Teleported Content

Impact: MEDIUM - When using scoped styles with Teleport, the styles may not apply correctly to teleported elements. This is a known limitation related to how Vue's scoped style attributes work with elements rendered outside the component's DOM tree.

Task Checklist

  • Test scoped styles on teleported content
  • Use :deep() selector or non-scoped styles for teleported content
  • Consider CSS modules as an alternative
  • Keep teleported content styles in a separate non-scoped style block

Problem - Scoped Styles Not Applied:

<template>
  <Teleport to="body">
    <div class="modal">
      <p class="modal-text">This text may not be styled!</p>
    </div>
  </Teleport>
</template>

<style scoped>
/* These styles may NOT apply to teleported content */
.modal {
  background: white;
  padding: 20px;
}

.modal-text {
  color: blue;  /* May not work */
}
</style>

Solution 1 - Use Non-Scoped Styles for Teleported Content:

<template>
  <Teleport to="body">
    <div class="my-modal">
      <p class="my-modal-text">This text will be styled</p>
    </div>
  </Teleport>
</template>

<style scoped>
/* Component-specific styles */
.button { color: blue; }
</style>

<style>
/* Non-scoped styles for teleported content */
/* Use specific class names to avoid conflicts */
.my-modal {
  background: white;
  padding: 20px;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.my-modal-text {
  color: blue;
}
</style>

Solution 2 - Use :deep() Selector:

<template>
  <Teleport to="body">
    <div class="modal">
      <p class="modal-text">Styled with :deep()</p>
    </div>
  </Teleport>
</template>

<style scoped>
:deep(.modal) {
  background: white;
  padding: 20px;
}

:deep(.modal-text) {
  color: blue;
}
</style>

Solution 3 - CSS Modules:

<template>
  <Teleport to="body">
    <div :class="$style.modal">
      <p :class="$style.modalText">Styled with CSS modules</p>
    </div>
  </Teleport>
</template>

<style module>
.modal {
  background: white;
  padding: 20px;
}

.modalText {
  color: blue;
}
</style>

Multi-Root Components with Teleport

Using Teleport as one of multiple root nodes causes additional issues:

<template>
  <!-- Multi-root component -->
  <button @click="open = true">Open</button>
  <Teleport to="body">
    <div class="modal">Content</div>
  </Teleport>
</template>

<!-- Warning: class/style attributes may not be inherited -->

Pass classes explicitly to avoid inheritance issues:

<template>
  <button @click="open = true">Open</button>
  <Teleport to="body">
    <div :class="['modal', $attrs.class]" :style="$attrs.style">
      Content
    </div>
  </Teleport>
</template>

Best Practice: Dedicated Modal Styles

Create a dedicated stylesheet for modal/overlay components:

/* modal-styles.css */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: white;
  border-radius: 8px;
  padding: 24px;
  max-width: 500px;
  width: 90%;
}
<script setup>
import './modal-styles.css'
</script>

<template>
  <Teleport to="body">
    <div v-if="open" class="modal-overlay">
      <div class="modal-content">
        <slot />
      </div>
    </div>
  </Teleport>
</template>

Reference