You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fourth/layout/components/AppMain.vue

44 lines
2.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<template>
<section class="app-main">
<transition name="fade" mode="out-in">
<!-- <router-view :key="key"></router-view> -->
<router-view></router-view>
</transition>
</section>
</template>
<script>
export default {
name: 'AppMain',
computed: {
// key() {
// return this.$route.name !== undefined ? this.$route.name + +new Date() : this.$route + +new Date()
// }
}
}
</script>
#abc
<template>
<!-- 使用 `section` 元素作为容器类名为 `app-main`通常这个元素会用于承载页面的主体内容部分在整个页面布局结构中扮演重要角色例如展示各种业务模块数据展示区域等 -->
<section class="app-main">
<!-- 使用 Vue.js `<transition>` 组件设置过渡效果的名称为 `fade`过渡模式为 `out-in`这种过渡模式意味着旧元素先执行离开过渡淡出完成后新元素再执行进入过渡淡入用于在路由视图切换时不同页面组件切换时实现平滑的过渡动画效果 -->
<transition name="fade" mode="out-in">
<!-- 原本此处使用 `:key` 绑定了一个计算属性 `key`目前代码中该计算属性被注释掉了用于给 `<router-view>` 组件添加一个唯一标识当路由变化且 `key` 值改变时会强制重新渲染 `<router-view>` 对应的组件实现更有效的组件更新和过渡效果展示现在虽然没有绑定 `key` `<router-view>` 组件依然用于渲染与当前路由匹配的组件内容也就是展示具体的页面内容部分 -->
<router-view></router-view>
</transition>
</section>
</template>
<script>
export default {
name: 'AppMain',
computed: {
// 以下是一个被注释掉的计算属性 `key` 的定义。其目的是为了给 `<router-view>` 组件生成一个动态的、唯一的标识(`key`)。
// 通过判断 `this.$route.name` 是否有定义来生成不同的 `key` 值。如果 `$route.name` 存在,那么 `key` 值就是 `$route.name` 与当前时间戳(通过 `+new Date()` 获取)拼接而成,这样每次路由切换且路由名称改变时,`key` 值就会改变,强制 `<router-view>` 重新渲染对应的组件;如果 `$route.name` 不存在,就用整个 `$route` 对象与当前时间戳拼接作为 `key` 值,同样也是为了保证在路由相关信息变化时能够触发组件的重新渲染,以配合 `<transition>` 组件实现更好的过渡动画效果等功能。不过目前代码中该计算属性处于注释状态,暂时未生效。
// key() {
// return this.$route.name!== undefined? this.$route.name + +new Date() : this.$route + +new Date()
// }
}
}
</script>