美文网首页
vue-router路由跳转

vue-router路由跳转

作者: 嗯哼_3395 | 来源:发表于2018-07-07 15:15 被阅读0次

    vue路由跳转部分的内容

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <script src="vue.js"></script>
        <script src="vue-router.js"></script>
    </head>
    <body>
        <div id="app">
            <router-link to="/">index</router-link>
            <router-link to="/list">list</router-link>
            <router-view></router-view>
            {{flag}}
        </div>
    </body>
    <script>
    var index={
        data:function(){
            return{
                name:"JayChou"
            }
        },
        // beforeRouteEnter:function(to,from,next){
        //  setTimeout(function(){
        //      next(function(vm){
        //          vm.name=JayChou
        //      });
        //  },2000)
            
        // },
        beforeRouteLeave:function(to,from,next){
            console.log("update");
            next();
        },
        template:"<h1>{{name}}</h1>"
    }
    var list={
        template:"<h1>list</h1>"
    }
        var app=new Vue({
            el:"#app",
            data:{
                flag:false
            },
            created:function(){
                this.flag=true;
                this.$router.beforeEach(function(to,from,next){
                    // console.log("beforeEach");
                    next();
                    this.flag=true
                }.bind(this));
    
            },
            router:new VueRouter({
                routes:[
                    {
                        path:"/",
                        component:index
                    },
                    {
                        path:"/list",
                        component:list
                    }
                ]
            })
        })
    </script>
    </html>
    

    相关文章

      网友评论

          本文标题:vue-router路由跳转

          本文链接:https://www.haomeiwen.com/subject/etgwuftx.html