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(備注博客園)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM