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

4.7 KiB

title, impact, impactDescription, type, tags
title impact impactDescription type tags
KeepAlive Include/Exclude Requires Component Name MEDIUM The include and exclude props match against component name option, which must be explicitly declared gotcha
vue3
keepalive
component-name
include
exclude
sfc

KeepAlive Include/Exclude Requires Component Name

Impact: MEDIUM - When using include or exclude props on KeepAlive, the matching is done against the component's name option. Components without an explicit name will not match and caching behavior will be unexpected.

Task Checklist

  • Declare name option on components used with include/exclude
  • Use defineOptions({ name: '...' }) in <script setup>
  • Note: Since Vue 3.2.34, SFC filename is auto-inferred as name
  • Verify names match exactly (case-sensitive)

The Problem

<!-- App.vue -->
<template>
  <KeepAlive include="TabA,TabB">
    <component :is="currentTab" />
  </KeepAlive>
</template>
<!-- TabA.vue - NO NAME DECLARED -->
<script setup>
// No name option - will NOT match "TabA" in include!
const count = ref(0)
</script>

<template>
  <div>Count: {{ count }}</div>
</template>

Result: TabA is NOT cached because it has no name option to match against.

Solutions

Solution 1: Use defineOptions (Vue 3.3+)

<!-- TabA.vue -->
<script setup>
import { ref } from 'vue'

defineOptions({
  name: 'TabA'  // Now matches include="TabA"
})

const count = ref(0)
</script>

<template>
  <div>Count: {{ count }}</div>
</template>

Solution 2: Dual Script Block

<!-- TabA.vue -->
<script>
export default {
  name: 'TabA'
}
</script>

<script setup>
import { ref } from 'vue'
const count = ref(0)
</script>

<template>
  <div>Count: {{ count }}</div>
</template>

Solution 3: Rely on Auto-Inference (Vue 3.2.34+)

Since Vue 3.2.34, SFCs using <script setup> automatically infer their name from the filename:

TabA.vue  -> name is "TabA"
UserProfile.vue -> name is "UserProfile"
my-component.vue -> name is "my-component" (kebab-case preserved)
<!-- Works automatically since Vue 3.2.34+ -->
<!-- File: TabA.vue -->
<script setup>
import { ref } from 'vue'
const count = ref(0)
</script>

<template>
  <div>Count: {{ count }}</div>
</template>
<!-- App.vue -->
<template>
  <!-- Matches filename "TabA" -->
  <KeepAlive include="TabA">
    <component :is="currentTab" />
  </KeepAlive>
</template>

Common Mistakes

Mistake 1: Name Doesn't Match

<script>
export default {
  name: 'tab-a'  // lowercase kebab-case
}
</script>
<template>
  <!-- DOESN'T MATCH - include uses PascalCase -->
  <KeepAlive include="TabA">
    <component :is="currentTab" />
  </KeepAlive>
</template>

Fix: Ensure names match exactly:

<KeepAlive include="tab-a">  <!-- or change component name to 'TabA' -->

Mistake 2: Dynamic Components Without Names

<script setup>
import { defineAsyncComponent } from 'vue'

// Async component - might not have name!
const AsyncTab = defineAsyncComponent(() => import('./Tab.vue'))
</script>

Fix: Ensure the imported component has a name declared.

Mistake 3: Using Props in Options API

<script>
export default {
  // This doesn't set the component name!
  props: ['name']  // 'name' prop is different from component name option
}
</script>

Debugging Name Issues

Check what name Vue sees for your component:

<script setup>
import { getCurrentInstance, onMounted } from 'vue'

onMounted(() => {
  const instance = getCurrentInstance()
  console.log('Component name:', instance?.type?.name)
  console.log('Component __name:', instance?.type?.__name)
})
</script>

Using Different Match Formats

<template>
  <!-- String (comma-delimited) -->
  <KeepAlive include="TabA,TabB,TabC">
    <component :is="current" />
  </KeepAlive>

  <!-- RegExp -->
  <KeepAlive :include="/^Tab/">
    <component :is="current" />
  </KeepAlive>

  <!-- Array -->
  <KeepAlive :include="['TabA', 'TabB']">
    <component :is="current" />
  </KeepAlive>
</template>

Key Points

  1. Name must match exactly - Case-sensitive string matching
  2. Vue 3.2.34+ auto-infers name - From filename for <script setup> SFCs
  3. Use defineOptions - Clean way to set name in <script setup>
  4. Debug with getCurrentInstance - Check what name Vue actually sees
  5. Multiple formats available - String, RegExp, or Array for include/exclude

Reference