- 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: 下拉刷新 / 上拉加载 - 产品首页: 添加业务联系 - 文档: 清理过时文件,补充缺失规范章节
3.4 KiB
3.4 KiB
title, impact, impactDescription, type, tags
| title | impact | impactDescription | type | tags | |||||
|---|---|---|---|---|---|---|---|---|---|
| Boolean Prop Type Order Affects Casting Behavior | MEDIUM | Wrong type order causes boolean props to be parsed as empty strings instead of true | gotcha |
|
Boolean Prop Type Order Affects Casting Behavior
Impact: MEDIUM - When a prop accepts multiple types including both Boolean and String, the order in the type array determines how attribute-only syntax (e.g., <Component disabled />) is parsed. Incorrect ordering can result in "" (empty string) instead of true.
Vue applies special boolean casting rules, but String appearing before Boolean disables this casting.
Task Checklist
- Place
BooleanbeforeStringin type arrays when you want boolean casting - Test attribute-only syntax (
<Component disabled />) to verify expected behavior - Consider using only
Booleantype if the prop is truly boolean - Document the expected usage if both String and Boolean are intentional
Incorrect:
<script setup>
// WRONG: String before Boolean disables boolean casting
defineProps({
disabled: [String, Boolean] // disabled="" is parsed as empty string ""
})
</script>
<!-- In parent template -->
<MyComponent disabled /> <!-- props.disabled === "" (empty string, not true!) -->
<script setup>
defineProps({
// PROBLEMATIC: Order matters and may cause confusion
loading: [String, Boolean], // <Component loading /> gives ""
active: [Boolean, String] // <Component active /> gives true
})
</script>
Correct:
<script setup>
// CORRECT: Boolean before String enables boolean casting
defineProps({
disabled: [Boolean, String] // <Component disabled /> parsed as true
})
</script>
<!-- All of these work as expected -->
<MyComponent disabled /> <!-- props.disabled === true -->
<MyComponent :disabled="true" /> <!-- props.disabled === true -->
<MyComponent :disabled="false" /> <!-- props.disabled === false -->
<MyComponent disabled="custom" /> <!-- props.disabled === "custom" -->
<script setup>
// BEST: Use only Boolean if you don't need String values
defineProps({
disabled: Boolean // Clear intent, no ambiguity
})
</script>
Boolean Casting Rules
| Prop Declaration | Template Usage | Resulting Value |
|---|---|---|
Boolean |
<C disabled /> |
true |
Boolean |
<C /> (absent) |
false |
[Boolean, String] |
<C disabled /> |
true |
[String, Boolean] |
<C disabled /> |
"" (empty string) |
[Boolean, Number] |
<C disabled /> |
true |
[Number, Boolean] |
<C disabled /> |
true |
Note: The String type is special - it's the only type that overrides Boolean casting when placed first.
When to Use Multiple Types
<script setup>
// Use case: Prop can be a boolean toggle OR a string configuration
defineProps({
// Animation can be true/false OR a timing string like "fast", "slow"
animate: {
type: [Boolean, String], // Boolean first for casting
default: false
}
})
</script>
<!-- Usage examples -->
<Dialog animate /> <!-- true - use default animation -->
<Dialog :animate="false" /> <!-- false - no animation -->
<Dialog animate="slow" /> <!-- "slow" - custom timing -->