博客
关于我
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/

你可能感兴趣的文章
Python 中的线程
查看>>
Python 中的继承机制是什么样的?
查看>>
python读写excel之xlrd&xlwt&xlutils组合
查看>>
Python 中的装饰器是什么?
查看>>
Python 中的装饰器是如何工作的,有哪些实际应用场景?
查看>>
python读excel
查看>>
Python 中读取 CSV 文件-ChatGPT4o作答
查看>>
Python 之 filecmp
查看>>
python请求html_使用Python请求获取HTML?
查看>>
Python 之匿名函数和偏函数
查看>>
python 之栈的实现
查看>>
python语音播放
查看>>
python语言:装饰器原理
查看>>
Python 交互式数据可视化详解
查看>>
python语言有哪些优点和缺点_Python有哪些优缺点,你了解吗?
查看>>
Python 从入门到精通:30天速成教程到底有多狠?你能坚持下来吗?
查看>>
Python 从数据库中存储和检索密码的最安全方法
查看>>
Python语言及其应用 - 知识点遍历
查看>>
Python 优化提速的 8 个小技巧
查看>>
Python 余弦相似度与皮尔逊相关系数 计算
查看>>