vue-router transition 路由切换效果

所需更改文件  App.vue

 1 //template结构:
 2 
 3 <template> 
 4   <div id="app"> 
 5     <div id="nav">
 6       <router-link to="/come">Come</router-link>
 7     </div>
 8   <transition :name="transitionName"> 
 9       <router-view class="child-view"></router-view> 
10   </transition> 
11   </div> 
12 </template>
13 
14 //script结构:
15 
16 <script> 
17 
18 export default { 
19   name: 'app', 
20   data () { 
21     return { 
22       transitionName: 'slide-left' 
23     } 
24   }, 
25 mounted () { 
26 },
27 
28 //监听路由的路径,可以通过不同的路径去选择不同的切换效果 
29 watch: {
30   '$route' (to, from) {
31   //    console.log('现在路由:',to.path.split('/')[1],'来自路由:',from.path.split('/')[1],'现在的动画:',this.transitionName)
32     const toDepth = to.path.split('/').length
33     const fromDepth = from.path.split('/').length
34     this.transitionName = toDepth < fromDepth ? 'slide-right' : 'slide-left'
35     }
36   }
37 
38 } 
39 </script>
40 
41 //style结构:
42 
43 <style>
44 
45 .child-view { 
46   margin: 300px auto; 
47   width: 100%; 
48   height: 100%; 
49   transition: all .5s cubic-bezier(.55,0,.1,1); 
50 } 
51 .slide-left-enter, .slide-right-leave-active { 
52   opacity: 0; 
53   -webkit-transform: translate(30px, 0); 
54   transform: translate(30px, 0); 
55 } 
56 .slide-left-leave-active, .slide-right-enter { 
57   opacity: 0; 
58   -webkit-transform: translate(-30px, 0); 
59   transform: translate(-30px, 0); 
60 }
61 </style>

  如需交流可加博主QQ:602697966(备注博客园)

转载于:https://www.cnblogs.com/yzyh/p/7298038.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值