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. JDK8 BigDecimal API-创建BigDecimal源码浅析二

    第二篇,慢慢来 根据指数调整有效小数位数 // 上一篇由字符串创建BigDecimal代码中,有部分代码没有给出,这次补上 // 这个是当解析字符数组时存在有效指数时调整有小小数位数方法 privat ...

  2. The Non-Inverting Amplifier Output Resistance by Adrian S. Nastase [转载]

    Source Address: http://masteringelectronicsdesign.com/the-non-inverting-amplifier-output-resistance/ ...

  3. Java IO和Java NIO 和通道 在文件拷贝上的性能差异分析

    1.  在JAVA传统的IO系统中,读取磁盘文件数据的过程如下: 以FileInputStream类为例,该类有一个read(byte b[])方法,byte b[]是我们要存储读取到用户空间的缓冲区 ...

  4. Godot-富文本

    作用:添加链接(比如赞助网站,或者相关站点什么的) 效果如下: (引用Godot官网) Introduction RichTextLabel allows the display of complex ...

  5. A Simple Nim (SG打表找规律)

    题意:有n堆石子,每次可以将其中一堆分为数量不为0的3堆,或者从其中一堆中拿走若干个,最终拿完的那个人赢. 思路:直接暴力SG状态,然后找出其中的规律,异或一下每一堆的状态就可以了. #include ...

  6. 遍历table明细是否为空

    //循环遍历 <tbody id="linedata2">,获取每行值对比 $("#linedata2 tr").each(function(i,n ...

  7. 软件测试实验四----mujava变异测试

    1.整个路径结构 2.具体内容 2.1mujava的安装 2.1.1更改CLASSPATH环境变量,使命令行可以找到mujava的路径,方便之后mujava的使用. 2.1.2在系统某一路径下按照格式 ...

  8. create-react-app不暴露配置设置proxy代理

    此方法可以在不暴露配置的情况下直接设置代理,非常便捷 在package.json里添加 "proxy":"http://institute.dljy.lzdev" ...

  9. source insight 4.0.86.0 安装过程中出现的问题

    1.sourceinsight_4.0.86.0-setup.exe 2.sourceinsight4.exe覆盖安装目录中的sourceinsight4.exe 3.导入lic文件 过程中360会将 ...

  10. selenium span[contains]中使用变量

    province = '湖南' driver.find_element_by_xpath('//span[contains(text(),"'+province+'").click ...