1、route.js文件

import Vue from 'vue'
import Router from 'vue-router' Vue.use(Router) const router = new Router({
routes: [
{
path: '/',
name: 'login',
component: () => import('./views/login.vue')
},
{
path: '/schools',
name: 'schools',
component: () => import('./views/schools/main.vue')
},
{
path: '/main/:id',
name: 'main',
component: () => import('./views/report/main.vue'),
redirect: '/main/:id/class',
children: [
{
path: '/main/:id/teacher',
name: 'teacherMain',
component: () => import('./views/teacher/main.vue'),
},
{
path: '/main/:id/teacher/:gradeId/:subjectId',
name: 'teacherMain',
component: () => import('./views/teacher/main.vue'),
},
{
path: '/main/:id/class',
name: 'classMain',
component: () => import('./views/class/main.vue'),
},
]
},
{
path: '**', // 错误路由
redirect: '/login' //重定向
}
]
}) // 全局路由守卫
router.beforeEach((to, from, next) => {
function getCookie(name) {
let arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
if (arr = document.cookie.match(reg))
return decodeURIComponent(arr[2]);
else
return null;
} // to: Route: 即将要进入的目标 路由对象
// from: Route: 当前导航正要离开的路由
// next: Function: 一定要调用该方法来 resolve 这个钩子。执行效果依赖 next 方法的调用参数。 let isLogin = getCookie("localtoken") !== null; // 是否登录 // 未登录状态;当路由到nextRoute指定页时,跳转至login
if (!isLogin && to.name !== 'login') {
router.push({ name: 'login' });
} // 已登录状态;当路由到login时,跳转至home
if (to.name === 'login') {
if (isLogin) {
router.push('/schools');
}
} next();
}); export default router;

2、路由跳转

2.1 页面跳转

        <router-link tag="nav" active-class="active" :to="'/main/'+schoolID+'/teacher'">
<a>教师</a>
<i></i>
</router-link>
<router-link tag="nav" active-class="active" :to="'/main/'+schoolID+'/class'">
<a>班</a>
<i></i>
</router-link>

2.2 js方法跳转

this.$router.push('/main/' + this.schoolID + '/teacher');

this.$router.push('/main/' + this.schoolID + '/teacher/' + this.nowGrade + "/" + this.nowSubject);

3、使用路由参数

    watch: {
//如果路由发生了变化,更新页面数据
$route(to, from) {
if (to.path !== from.path) {
this.schoolID = this.$route.params.id;
this.gradeId = this.$route.params.gradeId;
this.subjectId = this.$route.params.subjectId;
this.init();
}
}
},
data(){
return {
schoolID: this.$route.params.id,//学校 id
gradeId: this.$route.params.gradeId,
subjectId: this.$route.params.subjectId,
}
},

Vue route的使用的更多相关文章

  1. 深入浅出的webpack4构建工具--webpack4+vue+route+vuex项目构建(十七)

    阅读目录 一:vue传值方式有哪些? 二:理解使用Vuex 三:webpack4+vue+route+vuex 项目架构 回到顶部 一:vue传值方式有哪些? 在vue项目开发过程中,经常会使用组件来 ...

  2. vue route.go 载入刷新

    vue route 重新载入刷新: this.$router.go({path : 'path' , query: { param: this.param} })

  3. Vue Route Building the UI back-end framework

    Vue 的 路由就像ASP.NET MVC路径相似. 路由定义文件也是js格式的,我们都将这些文件放入到src的route文件中. 后台框架主入口: <template> <div ...

  4. vue route

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. Vue route部分简单高级用法

    一改变页面title的值   在开发时常常需要在切换到不同页面时改变浏览器的title值,那么我们就可以在定义路由的时候通过配置 meta 属性 来改变title值. import Vue from ...

  6. Vue:$route 和 $router 的区别

    参考: https://uzshare.com/view/788446 https://router.vuejs.org/zh/ $route 是“路由信息对象”,包括 path,params,has ...

  7. vue route 跳转

    index.js { path: '/grouporder/grouporderdetail/id/:id', name: '/grouporder/grouporderdetail/id/', co ...

  8. 借助 Vue 来构建单页面应用

    原文: https://github.com/MeCKodo/vue-tutorial 主题 Vue.js (1/2)Vue构建单页应用最佳实战 前言 我们将会选择使用一些vue周边的库 1.使用no ...

  9. Vue.js的库,包,资源的列表大全。

    官方资源 外部资源 社区 播客 官方示例 入门 开发工具 语法高亮 代码片段 自动补全 组件集合 库和插件 路由 ajax/数据 状态管理 校验 UI组件 i18n 示例 模板 脚手架 整合 插件/指 ...

随机推荐

  1. linux下python3(Setup)项目

    新建setup.py文件 写入 from setuptools import setup setup( name='tickets', #定义你项目的名称 py_modules=['tickets', ...

  2. 【论文速读】Shitala Prasad_ECCV2018】Using Object Information for Spotting Text

    Shitala Prasad_ECCV2018]Using Object Information for Spotting Text 作者和代码 关键词 文字检测.水平文本.FasterRCNN.xy ...

  3. 激光三角法点云重建分享——halcon 方法

    如今视觉应用方面单纯依靠2D图像解决问题存在很多问题.稳定性差.定位不准确.还有配合机器人抓取方面只能抓高度一致的物品.其实在Halcon算法库有非常强大的三维算法.包括点云重建.激光三角法(2D相机 ...

  4. Angular4 表单处理

  5. PowerDesigner 15的Table表视图的列显示Code

    PowerDesigner 15的图表的Table表视图一般显示成这样: 现在,我要将Code显示到Table表视图上,该怎么做?选择菜单:Tools→Display Preferences,弹出对话 ...

  6. python 2 和 python 3 的区别

    p2:重复代码语言不统一不支持中文input() 输入数字 获取数字输入字符串必须自己手动写引号raw_input 和p3中的 input 一样print可以加括号 也可以不加括号p2 中除法获取到的 ...

  7. Java运行环境

    Java 开发环境配置 在本章节中我们将为大家介绍如何搭建Java开发环境. Windows 上安装开发环境 Linux 上安装开发环境 安装 Eclipse 运行 Java Cloud Studio ...

  8. Java8-对map排序

    1.Java8对map按key排序 /** * @author : fengkun * @date : 19-3-10 * 内容 : Java8对map按key排序 */ public class S ...

  9. Spring AOP 简介

    Spring AOP 简介 如果说 IoC 是 Spring 的核心,那么面向切面编程就是 Spring 最为重要的功能之一了,在数据库事务中切面编程被广泛使用. AOP 即 Aspect Orien ...

  10. 自制操作系统Antz(8)——实现内核 (中) 扩展内核

    Antz系统更新地址: https://www.cnblogs.com/LexMoon/category/1262287.html 在前几天的任务中,我们已经简单实现了MBR,直接操作显示器和硬盘操作 ...