这篇文章给大家分享的是有关Vue中多元素过渡特效的示例分析的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
创新互联 专注于企业
成都营销网站建设 、网站重做改版、潞州网站定制设计、自适应品牌网站建设、
H5高端网站建设 、
商城建设 、集团公司官网建设、外贸营销网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为潞州等各大城市提供网站开发制作服务。为什么要使用Vue
Vue是一款友好的、多用途且高性能的JavaScript框架,使用vue可以创建可维护性和可测试性更强的代码库,Vue允许可以将一个网页分割成可复用的组件,每个组件都包含属于自己的HTML、CSS、JavaScript,以用来渲染网页中相应的地方,所以越来越多的前端开发者使用vue。
常见示例
最常见的多标签过渡是一个列表和描述这个列表为空消息的元素:
Sorry, no items found.
下面是一个例子
清空数据
重置
Sorry, no items found.
同标签名称
如果是相同标签名的元素切换时,Vue 为了效率只会替换相同标签内部的内容
由下面的示例可知,两个相同的p元素切换时,无过渡效果
因此,对于具有相同标签名的元素切换的情况,需要通过 key 特性设置唯一的值来标记以让 Vue 区分它们
替代if
在一些场景中,可以给通过给同一个元素的 key 特性设置不同的状态来代替 v-if 和 v-else
Save
Edit
上面的例子可以重写为
{{ isEditing ? 'Save' : 'Edit' }}
下面是一个例子
toggle
{{ isEditing ? 'Save' : 'Edit' }}
使用多个 v-if 的多个元素的过渡可以重写为绑定了动态属性的单个元素过渡
Edit
Save
Cancel
可以重写为
{{ buttonMessage }}
computed: {
buttonMessage: function () {
switch (this.docState) {
case 'saved': return 'Edit'
case 'edited': return 'Save'
case 'editing': return 'Cancel'
}
}
}下面是一个例子
过渡模式
先看下面这个例子
{{ isOn ? 'On' : 'Off' }}
在 “on” 按钮和 “off” 按钮的过渡中,两个按钮都被重绘了,一个离开过渡的时候另一个开始进入过渡。这是 的默认行为 - 进入和离开同时发生
同时生效的进入和离开的过渡不能满足所有要求,所以 Vue 提供了过渡模式
in-out: 新元素先进行过渡,完成之后当前元素过渡离开。
out-in: 当前元素先进行过渡,完成之后新元素过渡进入。
in-out
下面使用in-out来重写之前的开关按钮过渡
{{ isOn ? 'On' : 'Off' }}
out-in
下面使用out-in来重写之前的开关按钮过渡
{{ isOn ? 'On' : 'Off' }}
滑动过渡
当元素设置为绝对定位,并互相覆盖,实现透明度过渡效果
{{ isOn ? 'On' : 'Off' }}
下面是一个使用absolute和translate实现的类似滑动
如果设置in-out模式,将实现更酷的滑动效果
{{ isOn ? 'On' : 'Off' }}
多组件过渡
多个组件的过渡简单很多,不需要使用 key 特性。相反,只需要使用动态组件
下面是一个例子
切换页面
基本
文件
流程
错误
SQL
调试
请求信息 : 2026-06-01 08:21:35 HTTP/1.1 GET : /article/ccsido.html 运行时间 : 0.6229s ( Load:0.0063s Init:0.0011s Exec:0.6064s Template:0.0090s ) 吞吐率 : 1.61req/s 内存开销 : 2,250.08 kb 查询信息 : 12 queries 5 writes 文件加载 : 36 缓存信息 : 0 gets 0 writes 配置加载 : 130 会话信息 : SESSION_ID=p1efj662lldte0e94op7vpvja2
/www/wwwroot/tsicrk.com/index.php ( 1.09 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/ThinkPHP.php ( 4.61 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Think.class.php ( 12.26 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Storage.class.php ( 1.37 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Storage/Driver/File.class.php ( 3.52 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Mode/common.php ( 2.82 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Common/functions.php ( 53.56 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Hook.class.php ( 4.01 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/App.class.php ( 13.49 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Dispatcher.class.php ( 14.79 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Route.class.php ( 13.36 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Controller.class.php ( 11.23 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/View.class.php ( 7.59 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Library/Behavior/BuildLiteBehavior.class.php ( 3.68 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Library/Behavior/ParseTemplateBehavior.class.php ( 3.88 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Library/Behavior/ContentReplaceBehavior.class.php ( 1.91 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Conf/convention.php ( 11.15 KB ) /www/wwwroot/tsicrk.com/App/Common/Conf/config.php ( 2.14 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Lang/zh-cn.php ( 2.55 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Conf/debug.php ( 1.49 KB ) /www/wwwroot/tsicrk.com/App/Home/Conf/config.php ( 0.31 KB ) /www/wwwroot/tsicrk.com/App/Home/Common/function.php ( 3.33 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Library/Behavior/ReadHtmlCacheBehavior.class.php ( 5.62 KB ) /www/wwwroot/tsicrk.com/App/Home/Controller/ArticleController.class.php ( 6.02 KB ) /www/wwwroot/tsicrk.com/App/Home/Controller/CommController.class.php ( 1.60 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Model.class.php ( 60.11 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Db.class.php ( 32.43 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Db/Driver/Pdo.class.php ( 16.74 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Cache.class.php ( 3.83 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Cache/Driver/File.class.php ( 5.87 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Template.class.php ( 28.16 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Template/TagLib/Cx.class.php ( 22.40 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Template/TagLib.class.php ( 9.16 KB ) /www/wwwroot/tsicrk.com/App/Runtime/Cache/Home/7540f392f42b28b481b30614275e4e55.php ( 17.71 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Library/Behavior/WriteHtmlCacheBehavior.class.php ( 0.97 KB ) /www/wwwroot/tsicrk.com/ThinkPHP/Library/Behavior/ShowPageTraceBehavior.class.php ( 5.24 KB )
[ app_init ] --START-- Run Behavior\BuildLiteBehavior [ RunTime:0.000005s ] [ app_init ] --END-- [ RunTime:0.000026s ] [ app_begin ] --START-- Run Behavior\ReadHtmlCacheBehavior [ RunTime:0.000270s ] [ app_begin ] --END-- [ RunTime:0.000289s ] [ view_parse ] --START-- [ template_filter ] --START-- Run Behavior\ContentReplaceBehavior [ RunTime:0.000056s ] [ template_filter ] --END-- [ RunTime:0.000076s ] Run Behavior\ParseTemplateBehavior [ RunTime:0.006137s ] [ view_parse ] --END-- [ RunTime:0.006177s ] [ view_filter ] --START-- Run Behavior\WriteHtmlCacheBehavior [ RunTime:0.000164s ] [ view_filter ] --END-- [ RunTime:0.000179s ] [ app_end ] --START--
1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') LIMIT 1' at line 1
[ SQL语句 ] : SELECT `id`,`pid`,`navname` FROM `cx_nav` WHERE ( id= ) LIMIT 1 1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') LIMIT 1' at line 1
[ SQL语句 ] : SELECT `id`,`navname` FROM `cx_nav` WHERE ( id= ) LIMIT 1 1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
[ SQL语句 ] : SELECT `id`,`navname` FROM `cx_nav` WHERE ( pid= ) [8] Undefined index: pid /www/wwwroot/tsicrk.com/App/Home/Controller/ArticleController.class.php 第 47 行. [8] Undefined index: db_host /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Db.class.php 第 120 行. [8] Undefined index: db_port /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Db.class.php 第 121 行. [8] Undefined index: db_name /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Db.class.php 第 122 行.
0.6229s