- 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.3 KiB
3.3 KiB
title, impact, impactDescription, type, tags
| title | impact | impactDescription | type | tags | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Import h Globally in Vue 3 Render Functions | HIGH | Vue 3 requires explicit h import; using Vue 2 patterns causes runtime errors | gotcha |
|
Import h Globally in Vue 3 Render Functions
Impact: HIGH - In Vue 2, the h function (createElement) was passed as an argument to render functions. In Vue 3, h must be explicitly imported from 'vue'. Using Vue 2 patterns causes runtime errors.
Task Checklist
- Import
hfrom 'vue' at the top of files using render functions - Remove the
hparameter from render function signatures - Update all render functions when migrating from Vue 2
Incorrect (Vue 2 pattern - broken in Vue 3):
// WRONG: Vue 2 pattern - h is not passed as argument in Vue 3
export default {
render(h) { // h is undefined in Vue 3!
return h('div', [
h('span', 'Hello')
])
}
}
// WRONG: Using createElement alias from Vue 2
export default {
render(createElement) { // Also undefined
return createElement('div', 'Hello')
}
}
Correct (Vue 3 pattern):
// CORRECT: Import h from vue
import { h } from 'vue'
export default {
render() {
return h('div', [
h('span', 'Hello')
])
}
}
With Composition API
import { h, ref } from 'vue'
export default {
setup() {
const count = ref(0)
// Return a render function from setup
return () => h('div', [
h('button', { onClick: () => count.value++ }, `Count: ${count.value}`)
])
}
}
With script setup (Not Recommended)
<script setup>
import { h, ref } from 'vue'
const count = ref(0)
// Cannot return render function from script setup
// Must use a separate render option or template
</script>
<!-- script setup typically uses templates, not render functions -->
<template>
<div>
<button @click="count++">Count: {{ count }}</button>
</div>
</template>
If you need render functions with <script setup>, use the render option:
<script>
import { h, ref } from 'vue'
export default {
setup() {
const count = ref(0)
return () => h('button', { onClick: () => count.value++ }, count.value)
}
}
</script>
Component Resolution Change
In Vue 3, you must also explicitly resolve components:
Incorrect:
// Vue 2: Could use string names for registered components
render(h) {
return h('my-component', { props: { value: 1 } })
}
Correct:
import { h, resolveComponent } from 'vue'
export default {
render() {
// Must resolve component by name
const MyComponent = resolveComponent('my-component')
return h(MyComponent, { value: 1 })
}
}
// Or import the component directly (preferred)
import { h } from 'vue'
import MyComponent from './MyComponent.vue'
export default {
render() {
return h(MyComponent, { value: 1 })
}
}
Why This Changed
Vue 3's h is globally importable to:
- Enable tree-shaking (unused features can be removed)
- Support better TypeScript inference
- Allow use outside of component context