- 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: 下拉刷新 / 上拉加载 - 产品首页: 添加业务联系 - 文档: 清理过时文件,补充缺失规范章节
4.8 KiB
title, impact, impactDescription, type, tags
| title | impact | impactDescription | type | tags | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| RouterView Transitions Always Apply Despite Missing appear Prop | LOW | Initial page load with RouterView triggers transition animation even without the appear prop due to async navigation | gotcha |
|
RouterView Transitions Always Apply Despite Missing appear Prop
Impact: LOW - When using <Transition> with Vue Router's <RouterView>, the enter transition animation runs on initial page load even if you haven't added the appear prop. This differs from normal Transition behavior where appear is required for initial render animations. This happens because Vue Router's navigations are asynchronous, causing the component to mount after the initial render.
Task Checklist
- Be aware that RouterView transitions always animate on initial load
- If you want NO animation on initial load, you need to handle this explicitly
- Don't add
appearprop expecting it to change behavior - it's already effectively enabled - Consider whether initial animation is desired for your UX
Expected Behavior (Normal Transition):
<template>
<!-- Without appear: No animation on initial render -->
<Transition name="fade">
<div v-if="show">Content</div>
</Transition>
<!-- With appear: Animates on initial render -->
<Transition name="fade" appear>
<div v-if="show">Content</div>
</Transition>
</template>
RouterView Behavior (Different!):
<template>
<!-- RouterView transitions ALWAYS animate on initial load -->
<!-- The appear prop has no effect here -->
<RouterView v-slot="{ Component }">
<Transition name="fade">
<component :is="Component" />
</Transition>
</RouterView>
</template>
<!--
On initial page load:
1. Vue renders the app
2. Router resolves the route (async)
3. Component mounts AFTER initial render
4. Enter transition triggers (as if toggled from v-if="false" to v-if="true")
-->
Why This Happens
Vue Router navigations are asynchronous. The sequence is:
- Vue application mounts with empty RouterView
- Router resolves the initial route
- Route component is inserted into RouterView
- This insertion triggers the enter transition
Since the component wasn't present in the initial render and is "inserted" afterward, Vue treats it as a normal enter transition, not an initial render.
If You Want to Disable Initial Animation
<template>
<RouterView v-slot="{ Component }">
<Transition :name="isInitialLoad ? '' : 'fade'" mode="out-in">
<component :is="Component" />
</Transition>
</RouterView>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
const isInitialLoad = ref(true)
const router = useRouter()
// After first navigation completes, enable transitions
router.isReady().then(() => {
// Small delay to ensure initial render is complete
setTimeout(() => {
isInitialLoad.value = false
}, 0)
})
</script>
Alternative: Use CSS to Skip First Animation
<template>
<RouterView v-slot="{ Component }">
<Transition name="fade" mode="out-in">
<component :is="Component" :class="{ 'skip-initial': isInitialLoad }" />
</Transition>
</RouterView>
</template>
<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
const isInitialLoad = ref(true)
const router = useRouter()
router.isReady().then(() => {
isInitialLoad.value = false
})
</script>
<style>
.fade-enter-active,
.fade-leave-active {
transition: opacity 0.3s ease;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
}
/* Skip animation on initial load */
.skip-initial.fade-enter-active {
transition: none;
}
</style>
Standard RouterView Transition Pattern
If you're fine with initial animation (often desired), use the standard pattern:
<template>
<RouterView v-slot="{ Component, route }">
<Transition :name="route.meta.transition || 'fade'" mode="out-in">
<component :is="Component" :key="route.path" />
</Transition>
</RouterView>
</template>
<style>
.fade-enter-active,
.fade-leave-active {
transition: opacity 0.3s ease;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
}
/* Route-specific transitions via meta */
.slide-enter-active,
.slide-leave-active {
transition: transform 0.3s ease;
}
.slide-enter-from {
transform: translateX(100%);
}
.slide-leave-to {
transform: translateX(-100%);
}
</style>
// router.js
const routes = [
{
path: '/',
component: Home
},
{
path: '/about',
component: About,
meta: { transition: 'slide' } // Custom transition for this route
}
]