zoukankan      html  css  js  c++  java
  • vue-router勾子

     1 import Vue from 'vue'
     2 import VueRouter from 'vue-router'
     3 import parent from './transition.vue'
     4 Vue.use(VueRouter)
     5 
     6 const Home={template:`<div>Home内容</div>`}
     7 // const parent={template:`<div>parent内容</div>`}
     8 const page404={template:`
     9     <div><h2>error:404</h2></div>`,
    10     beforeRouteEnter:(to,from,next) => {
    11         console.log(to)
    12         console.log(from)
    13         // next(false)
    14         next()
    15     },
    16     beforeRouteLeave:(to,from,next) => {
    17         console.log(to)
    18         console.log(from)
    19         // next(false)
    20         next()
    21     }
    22 }
    23 
    24 const router=new VueRouter({
    25     mode:'history',
    26     base:__dirname,
    27     routes:[
    28         {path:'/',component:Home},
    29         {path:'/parent',component:parent,
    30             beforeEnter:(to,from,next) => {
    31                 console.log(to)
    32                 console.log(from)
    33                 // next(false)
    34                 next({path:'/'})
    35             }
    36     },
    37         {path:'*',component:page404}
    38     ]
    39 })
    40 
    41 new Vue({
    42     router,
    43     data(){
    44         return{
    45             aaa:'fade'
    46         }
    47     },
    48     template:`
    49         <div>
    50             <p>hello</p>
    51             <ul>
    52                 <li><router-link to="/">/</router-link></li>
    53                 <li><router-link to="/parent">parent</router-link></li>
    54                 <li><router-link to="/qqqqqqqqqqqqqqqqqqqqq">Where not here</router-link></li>
    55             </ul>
    56             <transition :name="aaa" mode="out-in">
    57                 <router-view></router-view>
    58             </transition>
    59         </div>
    60     `,
    61     watch:{
    62         '$route'(to,from){
    63             if(from.path=='/parent'){
    64                 this.aaa='fade1'
    65             }else{
    66                 this.aaa='fade2'
    67             }
    68         }
    69     }
    70 }).$mount("#app")
    View Code
  • 相关阅读:
    C语言 · 最小公倍数
    SSH实战 · SSH项目开发环境搭建
    C语言 · 回文数
    C语言 · 特殊回文数
    C语言 · 查找整数
    SSH实战 · SSH项目中怎么玩验证码
    SSH实战 · JAVA发送邮件相关
    SSH实战 · AJAX异步校验
    C语言 · 打印1-200之间的素数
    Jenkins权限设计错误解决办法
  • 原文地址:https://www.cnblogs.com/yijisi/p/11257508.html
Copyright © 2011-2022 走看看