- 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 | |||||
|---|---|---|---|---|---|---|---|---|---|
| Checkbox true-value/false-value Not Submitted in Forms | MEDIUM | true-value and false-value attributes don't affect form submission - unchecked boxes send nothing | capability |
|
Checkbox true-value/false-value Not Submitted in Forms
Impact: MEDIUM - Vue's true-value and false-value attributes only affect the JavaScript binding, NOT the actual form submission. Unchecked checkboxes are never included in form submissions by browsers, regardless of false-value.
This is a browser limitation, not a Vue issue. If you need to submit one of two values (like "yes"/"no" or "active"/"inactive"), use radio buttons instead of a checkbox.
Task Checklist
- Don't rely on
false-valuefor form submissions - it won't be sent - Use radio buttons when you need to submit one of exactly two values
- Remember
true-value/false-valueare for JavaScript state only - For form submissions with custom values, handle the transformation server-side or in submit handler
Problem - false-value not submitted:
<script setup>
import { ref } from 'vue'
const status = ref('no') // JavaScript value works correctly
</script>
<template>
<form action="/api/update" method="POST">
<!-- PROBLEM: When unchecked, nothing is submitted for this field -->
<!-- Server receives no "status" field at all, not "no" -->
<input
type="checkbox"
v-model="status"
true-value="yes"
false-value="no"
name="status"
>
<label>Active</label>
<!-- status.value correctly shows "yes" or "no" in Vue -->
<!-- But form submission only sends "status=yes" when checked -->
<!-- When unchecked, "status" field is completely missing -->
</form>
</template>
Solution 1 - Use radio buttons for two-value submission:
<script setup>
import { ref } from 'vue'
const status = ref('no')
</script>
<template>
<form action="/api/update" method="POST">
<!-- CORRECT: Radio buttons always submit a value -->
<label>
<input type="radio" v-model="status" value="yes" name="status">
Active
</label>
<label>
<input type="radio" v-model="status" value="no" name="status">
Inactive
</label>
<!-- Form always submits "status=yes" or "status=no" -->
</form>
</template>
Solution 2 - Handle in submit handler (for SPA/AJAX):
<script setup>
import { ref } from 'vue'
const isActive = ref(false)
async function submitForm() {
// Transform checkbox state to desired value before sending
const payload = {
status: isActive.value ? 'yes' : 'no'
}
await fetch('/api/update', {
method: 'POST',
body: JSON.stringify(payload)
})
}
</script>
<template>
<!-- For AJAX submission, checkbox is fine - transform in handler -->
<input type="checkbox" v-model="isActive">
<label>Active</label>
<button @click="submitForm">Save</button>
</template>
Solution 3 - Hidden input fallback:
<template>
<form action="/api/update" method="POST">
<!-- Hidden input provides fallback value -->
<input type="hidden" name="status" value="no">
<!-- Checkbox overrides with "yes" when checked -->
<input type="checkbox" name="status" value="yes" v-model="isActive">
<label>Active</label>
</form>
</template>