Vue-router(3)之 router-link 和 router-view 使用
router 导入
import Vue from 'vue'
import Router from 'vue-router'
import order from '@/view/New/order.vue'
import Son1 from '@/view/New/son1.vue'
import Son2 from '@/view/New/son2.vue'
import Son3 from '@/view/New/son3.vue' Vue.use(Router) export default new Router({
linkActiveClass: 'u-link--Active', // 这是链接激活时的class
routes: [
{ path: '/', redirect: '/4' },
{ path: '/4', name: 'order',redirect: '/4/son1', component: order, children: [
{ path: '/4/son1', name: "son1", component: Son1 },
{ path: '/4/son2', name: "son2", component: Son2 },
{ path: '/4/son3', name: "son3", component: Son3 }
]}
]
})
order.vue
<template>
<div class="detail">
<div class="box">
<p>父组件</p>
<router-link to="/4/son1" active-class="u-link--Active">首页</router-link>
<router-link to="/4/son2" active-class="u-link--Active">电影</router-link>
<router-link to="/4/son3" active-class="u-link--Active">关于</router-link>
</div>
<!-- 这是一个占位符,将来,通过路由规则,匹配到的组件,会被替换到 router-view 所在的位置 -->
<router-view></router-view>
</div>
</template> <style lang="less" scoped>
.detail {
margin: 5px;
padding: 10px;
border: 2px dashed salmon;
height: 400px;
background-color: #f6f6f6;
.box {
margin: 5px;
padding: 10px;
border: 2px dashed blue;
p {
color: salmon;
}
.u-link--Active {
color: aqua;
}
}
}
</style>
son.vue:
<template>
<div>
<h1>这是son1.vue 首页 子组件</h1>
</div>
</template> <style lang="less" scoped>
div {
margin: 5px;
padding: 10px;
border: 2px dashed red;
h1 {
font-size: 26px;
font-weight: 700;
color: orange;
}
}
</style>
son2:
<template>
<div>
<h1>这是son2.vue 电影 子组件</h1>
</div>
</template> <style lang="less" scoped>
div {
margin: 5px;
padding: 10px;
border: 2px dashed blue;
h1 {
font-size: 26px;
font-weight: 700;
color: red;
}
}
</style>
son3:
<template>
<div>
<h1>这是son3.vue 关于子组件</h1>
</div>
</template> <style lang="less" scoped>
div {
margin: 5px;
padding: 10px;
border: 2px dashed green;
h1 {
font-size: 26px;
font-weight: 700;
color: palevioletred;
}
}
</style>
路由规则的匹配过程
用户点击 页面的 路由链接
router-link
,点击的一瞬间,就会修改浏览器地址栏中的Hash地址;当 hash 地址被修改以后,会立即被
vue-router
监听到,然后进行 路由规则的 匹配;最终,找到 要显示的组件;当 路由规则匹配成功以后,就找到了要显示的组件,然后把这个组件,替换到页面指定的路由容器
router-view
中
设置路由高亮的两种方式和重定向
通过路由默认提供的
router-link-active
, 为这个类添加自己的高亮样式即可;通过路由构造函数,在传递路由配置对象的时候,提供
linkActiveClass
属性,来覆盖默认的高亮类样式;
测试:
Vue-router(3)之 router-link 和 router-view 使用的更多相关文章
- vue 组件开发、vue自动化工具、axios使用与router的使用(3)
一. 组件化开发 1.1 组件[component] 在网页中实现一个功能,需要使用html定义功能的内容结构,使用css声明功能的外观样式,还要使用js定义功能的特效,因此就产生了一个功能先关的代码 ...
- [ vue ] quasar框架踩坑:在vue文件外导入路由,执行router.push('/')没有效果
问题描述: 1. 如图所示的项目结构目录, axios.js 文件负责拦截全局请求和回复,我在拦截回复的代码中写了:如果服务器回复了一个401错误,则执行Router.push('/'),但是该方法失 ...
- 【Vue】【Router】手动跳转用 this.$router.push() 时 $router 未定义的问题
初入Vue,手写路由跳转时的问题: toXxxRoute: () => { this.$router.push({'path': '/xxx', 'name': 'xxx'}) } 由于使用了箭 ...
- Vue.js 的几点总结Watchers/router key/render
Vue.js 的几点总结,下面就是实战案例,一起来看一下. 第一招:化繁为简的Watchers 场景还原: 1 2 3 4 5 6 7 8 created(){ this.fetchPostLis ...
- [React Router v4] Style a Link that is Active with NavLink
We often need to be able to apply style to navigation links based on the current route. In React Rou ...
- vue路由中 Navigating to current location ("/router") is not allowed
报错原因:多次点击同一路由,导致路由被多次添加 解决方法: router/index中添加以下代码: //router/index.js Vue.use(VueRouter) //导入vue路由 co ...
- vue项目苹果微信端使用this.$router.go(-1)返回上一页,上一页并不会重新加载的问题
window.addEventListener('pageshow', function(e) { // 通过persisted属性判断是否存在 BF Cache if (e.persisted) { ...
- [React Router] Prevent Navigation with the React Router Prompt Component
In this lesson we'll show how to setup the Prompt component from React Router. We'll prompt with a s ...
- [Angular Router] Lazy loading Module with Auxiliary router
Found the way to handle Auxiliary router for lazy loading moudle and erge load module are different. ...
- 聊聊 Vue 的双向数据绑定,Model 如何改变 View,View 又是如何改变 Model 的
todo defineProperty() 参考: https://www.cnblogs.com/wangjiachen666/p/9883916.html
随机推荐
- Service总结
Service Service的应用场景,以及和Thread区别 开启Service的两种方式以及区别 Service基础 Service是什么? Service(服务)是一个可以在后台长时间运行而没 ...
- HihoCoder第八周:状态压缩 一
1044 : 状态压缩•一 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho在兑换到了喜欢的奖品之后,便继续起了他们的美国之行,思来想去,他们决定乘坐火车前 ...
- SQL语句--分组统计
一.教师号 星期号 是否有课1 2 有1 3 有2 1 有3 2 有`1 2 有写一条sql语句让你变为这样的表教师号 星期一 星期二 星期三1 2 12 13 1各星期下的数字表示:对应的教师在星期 ...
- 【Leetcode】交替打印FooBar
[问题]我们提供一个类: class FooBar { public void foo() { ; i < n; i++) { print("foo"); } } publi ...
- tornado+peewee-async+peewee+mysql(一)
前言: 需要异步操作MySQL,又要用orm,使用sqlalchemy需要加celery,觉得比较麻烦,选择了peewee-async 开发环境 python3.6.8+peewee-async0.5 ...
- python-arp 被动信息收集
python-arp 被动信息收集 概述 横向移动的时候由于局域网中可能存在未分配的IP,如果请求这些未分配的IP可能导致被发现(旁路检测设备),先可以做一下arp被动信息收集.当然对蜜罐类设备没用. ...
- 第八篇Django分页
Django分页 1.复杂版 data = [] , ): tmp = {"id": i, "name": "alex-{}".format ...
- slave_net_timeout, MASTER_HEARTBEAT_PERIOD, MASTER_CONNECT_RETRY,以及 MASTER_RETRY_COUNT设置和查看
在主从复制中,有几个参数是非常重要的,包括slave_net_timeout, MASTER_HEARTBEAT_PERIOD, MASTER_CONNECT_RETRY,以及 MASTER_RETR ...
- 【剑指Offer】面试题10- I. 斐波那契数列
题目 写一个函数,输入 n ,求斐波那契(Fibonacci)数列的第 n 项.斐波那契数列的定义如下: F(0) = 0, F(1) = 1 F(N) = F(N - 1) + F(N - 2) ...
- Adobe Photoshop CC2014 for MAC 详细破解步骤
1,安装Adobe Photoshop CC2014 for MAC,可以断网安装,如果不断网的话,需要申请一个Adobe ID,是免费申请. 2,下载破解工具,https://sdifen.ctfi ...