vue-router watch監控動畫


紅色框為增改內容!!!

1、src/router4.js

2、index.html設置樣式

3、main.js指向router4.js文件

 

router4.js全部代碼:
 1 import Vue from 'vue'
 2 import VueRouter from 'vue-router'
 3 Vue.use(VueRouter)
 4 
 5 const Home={template:`<div>Home內容</div>`}
 6 const parent={template:`<div>parent內容</div>`}
 7 
 8 const router=new VueRouter({
 9     mode:'history',
10     base:__dirname,
11     routes:[
12         {path:'/',component:Home},
13         {path:'/parent',component:parent}
14     ]
15 })
16 
17 new Vue({
18     router,
19     data(){
20         return{
21             aaa:'fade'
22         }
23     },
24     template:`
25         <div>
26             <p>hello</p>
27             <ul>
28                 <li><router-link to="/">/</router-link></li>
29                 <li><router-link to="/parent">parent</router-link></li>
30             </ul>
31             <transition :name="aaa" mode="out-in">
32                 <router-view></router-view>
33             </transition>
34         </div>
35     `,
36     watch:{
37         '$route'(to,from){
38             if(from.path=='/parent'){
39                 this.aaa='fade1'
40             }else{
41                 this.aaa='fade2'
42             }
43         }
44     }
45 }).$mount("#app")
View Code

 


免責聲明!

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



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