vue-11-路由嵌套-参数传递-路由高亮
1, 新建vue-router 项目
vue init webpack vue-router-test
是否创建路由: 是
2, 添加路由列表页
在 component下创建 NavList 页面
<template>
<div>
<div class="navlist">
<ul>
<li><router-link :to="index">首页</router-link></li>
<li><router-link :to="course">课程</router-link></li>
<li><router-link :to="master">专家</router-link></li>
</ul>
</div> </div>
</template> <script>
export default {
name: "NavList",
data() {
return {
index: "/",
course: "/course",
master: "/master",
}
}
}
</script> <style scoped>
.navlist {
width: %;
height: 50px;
background: #f1f1f1;
}
ul {
list-style: none;
}
li {
float: left;
margin: 20px;
}
</style>
3, 添加子页面
index.vue, master.vue, course.vue等, 仅展示 index.vue
<template>
<div>
<NavList/>
首页
</div>
</template> <script>
import NavList from "./NavList";
export default {
name: "index",
components: {NavList},
data() {
return { }
}
}
</script> <style scoped> </style>
4, 在index.js 中导入子页面, 配置路径和页面关系
import Vue from 'vue'
import Router from 'vue-router'
import index from '@/components/index'
import Course from '@/components/course'
import Master from '@/components/master'
import Java from '@/components/course/java'
import Python from '@/components/course/python' Vue.use(Router) export default new Router({
routes: [
{
path: '/',
name: 'index',
component: index
},
{
path: '/course',
name: 'Course',
component: Course,
},
{
path: '/master',
name: "Master",
component: Master
}
]
})
5, 在app vue 中, 添加路由显示位置
router-view
<template>
<div id="app">
<!--<img src="./assets/logo.png">-->
<!--<NavList/>-->
<router-view/> </div>
</template>
6, 使用 npm run dev 运行, 即可看到初始效果
7, 路由嵌套
有时候, 在二级页面下还需要新的子页面, 就需要使用路由嵌套功能
7.1) 在 component中添加 java.vue, python.vue 等子页面
<template>
<div>
java
</div>
</template> <script>
export default {
name: "java"
}
</script> <style scoped> </style>
7.2), 在course 中 引入路由嵌套
使用 router-link 进行页面跳转
添加 router-view 指定显示区域
路径导航使用全路径
<template>
<div>
<NavList/> <div class="left">
<ul>
<li><router-link :to="java">java</router-link></li>
<li><router-link :to="python">python</router-link></li>
<li>bigdata</li>
</ul>
</div> <div class="right">
视图区域
<router-view/>
</div> </div>
</template> <script>
import NavList from "./NavList";
export default {
name: "course",
components: {NavList},
data() {
return {
java: "/course/java",
python: "/course/python",
}
}
}
</script> <style scoped>
.left, .right {
float: left;
}
.left {
margin-left: ;
}
.right {
margin-left: 50px;
}
</style>
7.3) 在index.js 中指定 子嵌套关系
使用 redirect 指定一开始进入的默认页面
{
path: '/course',
name: 'Course',
component: Course,
// 默认进入重定向
redirect: "/course/java",
// 子嵌套
children: [
{
path: "java",
name: "Java",
component: Java
},
{
path: "python",
name: "Python",
component: Python
}
]
},
8, 参数传递
在vue中, 可以通过参数传递, 将值或者对象传递给路由子页面
8.1) 定义要传递的对象
data() {
return {
index: "/",
course: "/course",
master: "/master",
obj: {
name: "wenbronk",
age:
}
}
}
8.2), 在 router-link 中, 使用 :to={} 的形式进行传递参数
<li><router-link :to="{ name: 'Master', params:{count: 100, type: obj}}">专家</router-link></li>
8.3) 在 master 页面, 接受参数
<template>
<div>
专家: {{ $route.params.count }} - {{ $route.params.type.name }}
</div>
</template> <script>
export default {
name: "master"
}
</script> <style scoped> </style>
9, 路由高亮, 实现点击的呈现高亮效果
9.1), 在index.js 中, 添加 路由选中class名
默认是 router-link-active, 更改
mode: "history",
linkActiveClass: "active",
9.2), 在全局中配置, css 样式
.active {
color: red
}
9.3), 对于匹配 / 的, 会始终显示高亮, 需要添加 exact 属性;
<li><router-link :to="index" exact>首页</router-link></li>
vue-11-路由嵌套-参数传递-路由高亮的更多相关文章
- angular2系列教程(十一)路由嵌套、路由生命周期、matrix URL notation
今天我们要讲的是ng2的路由的第二部分,包括路由嵌套.路由生命周期等知识点. 例子 例子仍然是上节课的例子:
- 六、Vue-Router:基础路由处理、路由提取成单独文件、路由嵌套、路由传参数、路由高亮、html5的history使用
一.vue-router的安装 官网文档 [官网]:https://cn.vuejs.org/v2/guide/routing.html [router文档]:https://router.vuejs ...
- vue教程3-06 vue路由嵌套(多层路由),路由其他信息
多层嵌套: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- vue之路由嵌套,子路由
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- vue 路由嵌套高亮问题
正常路由嵌套是没有问题的,但是如果你已经在当前主路由页面了,然后再次点击主路由就会出现页面数据空白的情况 看代码: //主路由通过v-for循环出来 <div class="list- ...
- vue学习路由嵌套
1. 路由嵌套和参数传递 传参的两种形式: a.查询字符串:login?name=tom&pwd=123 {{$route.query}} ------ <li><route ...
- Vue学习手记03-路由跳转与路由嵌套
1.路由跳转 添加一个LearnVue.vue文件, 在router->index.js中 引入import Learn from '@/components/LearnVue' 在touter ...
- Vue总结第五天:vue-router (使用模块化(创建Vue组件)机制编程)、router-link 标签的属性、路由代码跳转、懒加载、路由嵌套(子路由)、路由传递数据、导航守卫)
Vue总结第五天:vue-router ✿ 路由(器)目录: □ vue中路由作用 □ vue-router基本使用 □ vue-router嵌套路由 □ vue-router参数传递 □ ...
- 060——VUE中vue-router之路由嵌套在文章系统中的使用方法:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
随机推荐
- http post 请求详解
一步一步了解http post 请求 (大白话版). 1.创建一 个 CloseableHttpClient 对象 CloseableHttpClient client = HttpClients. ...
- flink 读取kafka 数据,partition分配
每个并发有个编号,只会读取kafka partition % 总并发数 == 编号 的分区 如: 6 分区, 4个并发 分区: p0 p1 p2 p3 p4 p5 并发: 0 1 2 3 ...
- JavaScript -DOM 编程艺术 2nd 完
今日看完了这本书,做完了最后一个综合性例子.说实话收获良多,终于明白前端-h5 具体做什么 越学习越无知,这个看来真是一个真理. 后期计划: 1.CSS + DIV 布局深入了解,重点实战 2.Jav ...
- mysql官方的测试数据库employees超30万的数据,安装方法介绍
安装方法 1.mysql必须开启环境变量 2.shift右键官方数据库打开在命令行运行此窗口 3.进入cmd以后输入mysql -uroot -proot 回车 4.输入 source employ ...
- bootstrap-datepicker简单使用
粗略整理,可能存在其他的方式请大家多多指教 选择年份 html <div class="dropdown"> <label class="search- ...
- pageHelper的使用步骤,省略sql语句中的limit
1.引架包.注意版本问题 <dependency> <groupId>com.github.pagehelper</groupId> <artifactId& ...
- nginx的锁
一.原理 nginx的锁是基于共享内存实现的,这点跟redis中利用一个存储(也就是一个键值对)来实现锁的原理是一致的,每一项操作通过检查锁对象的lock域是否为0,来判断能否获取锁并尝试获取锁. 二 ...
- UDF函数 解码url
背景 URL 的编码 是ASCII十六进制格式.数仓接受到前端上报的URL,要对URL字段解码. 如要将 https"Fmybook.do%3Frequest_type%3D%26type% ...
- 写在HTTP协议之前
1.网络模型 OSI模型即:开放系统互连参考模型(Open System Interconnect 简称OSI)是国际标准化组织(ISO)和国际电报电话咨询委员会(CCITT)联合制定的开放系统互连参 ...
- 在使用可变数组过程中遇到*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFDictionary setObject:forKey:]: mutating method sent to immutable object'问题
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFD ...