博客
关于我
vue路由6:导航钩子
阅读量:324 次
发布时间:2019-03-04

本文共 1203 字,大约阅读时间需要 4 分钟。

index.html:

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Title</title></head><body><div id="app">    <div>        <router-link to="/">首页</router-link>        <router-link to="/login">登录</router-link>        <router-link to="/post">帖子管理</router-link>    </div>    <div>        <router-view></router-view>    </div></div><script src="../lib/vue.js"></script><script src="../lib/router.js"></script><script src="./js/app.js"></script></body></html>

app.js:

var routes = [    {        path: '/',        component:{            template: `            <p>这里是首页</p>        `        }    },{        path: '/login',        component: {            template: `            <p>这里是登录!</p>        `        }    },{        path: '/post',        component: {            template: `            <p>这里是帖子管理</p>        `        }    }];var router = new VueRouter({    routes: routes,});router.beforeEach(function(to, from, next){    var login_in = true;    if(!login_in && to.path == '/post'){        next('/login')    }else{        next();    }})router.afterEach(function(to, from){    console.log("to", to);    console.log("form", from);});var app = new Vue({    el: '#app',    router: router})

转载地址:http://jgvq.baihongyu.com/

你可能感兴趣的文章
Netty源码—3.Reactor线程模型四
查看>>
Netty源码—4.客户端接入流程一
查看>>
Netty源码—4.客户端接入流程二
查看>>
Netty源码—5.Pipeline和Handler一
查看>>
Netty源码—5.Pipeline和Handler二
查看>>
Netty源码—6.ByteBuf原理一
查看>>
Netty源码—6.ByteBuf原理二
查看>>
Netty源码—7.ByteBuf原理三
查看>>
Netty源码—7.ByteBuf原理四
查看>>
Netty源码—8.编解码原理一
查看>>
Netty源码—8.编解码原理二
查看>>
Netty源码解读
查看>>
netty的HelloWorld演示
查看>>
Netty的Socket编程详解-搭建服务端与客户端并进行数据传输
查看>>
Netty的网络框架差点让我一夜秃头,哭了
查看>>
Netty相关
查看>>
Netty简介
查看>>
Netty线程模型理解
查看>>
netty解决tcp粘包和拆包问题
查看>>
Netty速成:基础+入门+中级+高级+源码架构+行业应用
查看>>