黄子涵

初始渲染的过渡

可以通过 appear attribute 设置节点在初始渲染的过渡

<transition appear>
<!-- ... -->
</transition>

这里默认和进入/离开过渡一样,同样也可以自定义 CSS 类名。

<transition
appear
appear-class="custom-appear-class"
appear-to-class="custom-appear-to-class" (2.1.8+)
appear-active-class="custom-appear-active-class"
>
<!-- ... -->
</transition>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>初始渲染的过渡</title>
<script src="./vue.js"></script>
</head>
<body>
<div id="hzh">
<button @click="hzhShow = !hzhShow">
切换
</button>
<transition
appear
appear-class="hzh-appear-class"
appear-to-class="hzh-appear--to-class"
appear-active-class="hzh-appear-active-class"
>
<p v-if="hzhShow">
黄子涵
</p>
</transition>
</div>
<script>
new Vue({
el: '#hzh',
data: {
hzhShow: false
}
})
</script>
</body>

自定义 JavaScript 钩子:

<transition
appear
v-on:before-appear="customBeforeAppearHook"
v-on:appear="customAppearHook"
v-on:after-appear="customAfterAppearHook"
v-on:appear-cancelled="customAppearCancelledHook"
>
<!-- ... -->
</transition>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>初始渲染的过渡</title>
<script src="./vue.js"></script>
</head>
<body>
<div id="hzh">
<button @click="hzhShow = !hzhShow">
切换
</button>
<transition
appear
v-on:before-appear="hzhBeforeAppearHook"
v-on:appear="hzhAppearHook"
v-on:after-appear="hzhAfterAppearHook"
v-on:appear-cancelled="hzhAppearCancelledHook"
>
<p v-if="hzhShow">
黄子涵
</p>
</transition>
</div>
<script>
new Vue({
el: '#hzh',
data: {
hzhShow: false
}
})
</script>
</body>

在上面的例子中,无论是 appear attribute 还是 v-on:appear 钩子都会生成初始渲染过渡。

posted @   黄子涵  阅读(43)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示