Vue-router导航问题
现在的项目,用的是Vue,但当时用的时候,是边学边做的,上手确实比较简单,但是已经用Vue写了一个项目了,但是感觉对Vue的还是不是很深刻,用的都是比较简单的API,
现在回头看看,有些东西,非常的精巧和实用,现在回顾一下:
1.index
<ul @click='godetail'>
<li v-for="(item,index) in list">{{ index }}.{{ item.content }}</li>
</ul>
循环显示内容的时候,当需要显示index值的时候,index需要再item后面,如果index在item前面会显示item对象
2.params() 动态路由匹配
我们经常需要把某种模式匹配到的所有路由,全部映射到同个组件,例如我们有一个second组件,对于所有ID各不相同的用户,都要使用这个组件来渲染。
router.js配置
{
path: '/second/:id',
name: 'second',
component: second
}
vue页面
<p>
<router-link to="/second/foo">foo</router-link>
<router-link to="/second/bar">bar</router-link>
</p>
second {{ $route.params.id }}
<router-view></router-view>
在页面上显示的内容
/second/foo
和 /second/bar
都将映射到相同的路由second上,不用写新的vue组件。
3.命名式导航
在官网上介绍了一种命名路由,因为我一直是使用直接push()路径的,最近也在研究它俩的区别,
<router-link :to="{path:'/content/three',query:{openid:this.openid}}" >
用下来,个人还是比较喜欢直接push()路径的
例
一级路由里面有first和second路由
<router-link :to="{ name: 'first', params: {name:1} }">first</router-link>
<router-link :to="{ name: 'second', params: {name:2} }">second</router-link>
<router-view/>
然后first路由里面又有detail和test路由
<router-link :to="{ name: 'detail', params:{name:1}}">detail</router-link>
<router-link :to="{ name: 'test', params:{name:2}}">test</router-link>
<router-view></router-view>
在路由配置里
routes: [
{
path: '/first',
name: 'first',
component: first,
children: [
{
path: 'detail',
name: 'detail',
component: detail
},
{
path: 'test',
name: 'test',
component: test
},
{
path: '/', //first直接重定向至detail路由
name: 'detail',
redirect: 'detail'
}
]
},
{
path: '/second',
name: 'second',
component: second
},
{
path: '',
name: 'first',
redirect: 'first'
}
]
在测试过程中,首次进入,是可以直接重定向至first/detail路由的,但是当我点击second路由,再次点击first按钮时,就无法重定向至detail,只能手动点击,
重定向会失效,所以在使用命名导航时,尽量不要不要涉及父子路由嵌套的关系,最好是导航至某个特定页面。所以不建议大范围使用命名式导航
4.直接路径导航 <router-link :to="{path:'/content/three'}" >
在使用path导航的时候,也遇到一些问题
<router-link :to="{path:'/content/three'}" >
例如,是这样配置路由的,
{
path: 'index',
name: 'Index',
component: Index
},
{
path: 'sec',
name: 'Sec',
component: Sec,
children: [
{
path: 'repair',
component: repair
},
{
path: '/',
redirect: 'repair'
}
]
},
{
path: 'three',
name: 'Three',
component: Three
}
在使用repair路由时,有时需要传一些参数,
在此时的sec组件却不在active状态,究其原因,就是因为repair
携带了参数,与配置的路由不匹配,所以无法找到父级路由,所以用下来感觉都不是那么完美,也许自己理解的有误,但是目前目前遇到的情况确实是这样。
<router-link :to="{path:'/sec/repair',query:{id:this.id}}" >
Vue-router导航问题的更多相关文章
- vue router 导航守卫生命周期
导航守卫 导航守卫主要用来通过跳转或取消的方式守卫导航.有多种机会植入路由导航过程中:全局的, 单个路由独享的, 或者组件级的.(记住参数或查询的改变并不会触发进入/离开的导航守卫.你可以通过观察$r ...
- [Vue 牛刀小试]:第十四章 - 编程式导航与实现组件与 Vue Router 之间的解耦
一.前言 在上一章的学习中,通过举例说明,我们了解了 Vue Router 中命名路由.命名视图的使用方法,以及如何通过 query 查询参数传参,或者是采用 param 传参的方式实现路由间的参数传 ...
- Vue Router的导航解析过程
在我没读官方的vue router文档之前,我怎么也没想到路由的解析过程竟然有12步. 12步如下: 导航被触发. 在失活的组件里调用离开守卫beforeRouteLeave . 调用全局的 befo ...
- Vue Router 路由守卫:完整的导航解析流程
完整的导航解析流程 1 导航被触发. 2 在失活的组件里调用离开守卫. 3 调用全局的 beforeEach 守卫. 4 在重用的组件里调用 beforeRouteUpdate 守卫 (2.2+). ...
- Vue 2.0 + Vue Router + Vuex
用 Vue.js 2.x 与相配套的 Vue Router.Vuex 搭建了一个最基本的后台管理系统的骨架. 当然先要安装 node.js(包括了 npm).vue-cli 项目结构如图所示: ass ...
- Vue.js 2.x笔记:路由Vue Router(6)
1. Vue Router简介与安装 1.1 Vue Router简介 Vue Router 是 Vue.js 官方的路由管理器.它和 Vue.js 的核心深度集成,构建单页面应用. Vue Rout ...
- Vue Router学习笔记
前端的路由:一个地址对应一个组件 Vue Router中文文档 一.路由基本使用 第1步:导入Vue Router: <script src="https://unpkg.com/vu ...
- vue router.push(),router.replace(),router.go()和router.replace后需要返回两次的问题
转载:https://www.cnblogs.com/lwwen/p/7245083.html https://blog.csdn.net/qq_15385627/article/details/83 ...
- 深入浅出的webpack构建工具--webpack4+vue+router项目架构(十四)
阅读目录 一:vue-router是什么? 二:vue-router的实现原理 三:vue-router使用及代码配置 四:理解vue设置路由导航的两种方法. 五:理解动态路由和命名视图 六:理解嵌套 ...
- python 全栈开发,Day91(Vue实例的生命周期,组件间通信之中央事件总线bus,Vue Router,vue-cli 工具)
昨日内容回顾 0. 组件注意事项!!! data属性必须是一个函数! 1. 注册全局组件 Vue.component('组件名',{ template: `` }) var app = new Vue ...
随机推荐
- Vb6调用C#生成的dll
namespace ClassLibrary1 { [ClassInterface(ClassInterfaceType.AutoDispatch)] //注意这行,这行是关键 pub ...
- python 练习4
题目为信用卡消费管理系统: 主程序:main.py #!usr/bin/env python # encoding: utf-8 import conf,sys,time,re,os import j ...
- Quartz一次配置
1. 配置执行器的线程池 public ThreadPoolTaskExecutor defaultThreadPool() { ThreadPoolTaskExecutor executor = n ...
- Servers无法打开
有时候打开MyEclipse莫名Servers窗口挂掉, 出现"Could Not Create The View :An Unexpected Exception Was Thrown&q ...
- 走进JDK(十一)------LinkedHashMap
概述LinkedHashMap 继承自 HashMap,在 HashMap 基础上,通过维护一条双向链表,解决了 HashMap 不能随时保持遍历顺序和插入顺序一致的问题.除此之外,LinkedHas ...
- 【转】javaUDP套接字通信
Java UDP网络编程 - 最简单示例 转自 http://blog.csdn.net/wintys/article/details/3525643 /** *UDPServer *@autho ...
- Windows和Office激活汇总
Windows和Office是常用的软件.多数情况下,即使不激活,也会使用一部分功能.今天来看一下很多前辈的工作成果. 1. Windows 7&10 1.1 永久激活 通过key 分享几个常 ...
- org.apache.maven.archiver.mavenarchiver.getmanifest怎么解决
原因就是你的maven的配置文件不是最新的 1.help ->Install New Software -> add ->https://otto.takari.io/content ...
- ADO.NET学习笔记(1)
ADO.Net是.Net框架中为数据库的访问而封装的一个库.通过这个库我们可以简单便捷的访问数据库,并对数据库进行一些增删改查的操作,目前ADO.Net支持四种主流的数据库,分别是SQL.OLE DB ...
- 用pyspider爬取并解析json字符串
获取堆糖网站所有用户的id 昵称及主页地址 #!/usr/bin/env python # -*- encoding: utf-8 -*- # Created on 2016-06-21 13:57: ...