vue路由跳转的多种方式
1.router-link to 跳转
<router-link to="/child"><button>跳转</button></router-link>
2.this.$router.push("ComponentName") ,通过路由名称跳转
<button @click="go()">跳转</button>
go(){
this.$router.push("Child");
},
3.this.$router.push({path:"/child"}) ,通过路由的path跳转
<button @click="go2()">跳转</button>
go2(){
this.$router.push({path:"/child"});
},
4.带参数跳转 this.$router.push({path:"/child",params:{test:123}})
<button @click="go3()">带参数跳转</button>
go3(){
this.$router.push({path:"/child?test=123"})
},
这种跳转的路由地址和参数是这样的,用问号拼接的,

获取路由参数,this.$route.query.paramsName
<button @click="getParams()">获取路由参数</button>
getParams(){
console.log(this.$route.query.test); //
}
5.跳转到上一个路由,this.$router.go(-1)
<button @click="goback()">返回上一页</button>
goback(){
this.$router.go(-1);
}
6.命名路由的跳转,需要在配置路由上带上参数,<router-link :to={name:'ComponentName',params:{test:123}}></router-link>
{
name:"Children",
path:"/children/:test",
component:Children
}
<router-link :to="{name:'Children',params:{test:123}}"><button>跳转带参数</button></router-link>
这种跳转的路由地址和参数是这样的,用 / 拼接的,

获取路由参数:this.$route.params.xxx
<button @click="getParams()">获取路由参数</button>
getParams(){
console.log( this.$route.params.test);
}
vue路由跳转的多种方式的更多相关文章
- 详解vue 路由跳转四种方式 (带参数)
详解vue 路由跳转四种方式 (带参数):https://www.jb51.net/article/160401.htm 1. router-link ? 1 2 3 4 5 6 7 8 9 10 ...
- vue 路由跳转带参 方式query ,params
a.vue向b.vue传值 a.vue this.$router.push({ path: '/payType', query: { putUpList: this.putUpList, name:' ...
- vue路由跳转的方式
vue路由跳转有四种方式 1. router-link 2. this.$router.push() (函数里面调用) 3. this.$router.replace() (用法同push) 4. t ...
- Vue通信、传值的多种方式,详解
Vue通信.传值的多种方式,详解 转自:https://blog.csdn.net/qq_35430000/article/details/79291287 一.通过路由带参数进行传值 ①两个组件 A ...
- vue路由跳转报错解决
vue路由跳转: setTimeout(function () { console.log(this); this.$router.push("/login"); },800) 语 ...
- 去除vue路由跳转地址栏后的哈希值#
去除vue路由跳转地址栏后的哈希值#,我们只需要在路由跳转的管理文件router目录下的index.js中加上一句代码即可去掉哈希值# mode:"history" import ...
- Vue路由跳转到新页面时 默认在页面最底部 而不是最顶部 的解决
今天碰到一个问题 vue路由跳转到新的页面时会直接显示页面最底部 正常情况下是显示的最顶部的 而且好多路由中不是全部都是这种情况 折腾好长时间也没解决 最后在网上找到了解决办法 其实原理很 ...
- vue路由跳转取消上个页面的请求和去掉重复请求
vue路由跳转取消上个页面的请求和去掉重复请求 axios 的二次封装(拦截重复请求.异常统一处理) axios里面拦截重复请求
- Vue通信、传值的多种方式,详解(都是干货)
Vue通信.传值的多种方式,详解(都是干货) 可参考博客: https://blog.csdn.net/qq_35430000/article/details/79291287
随机推荐
- vue-webpack项目本地开发环境设置代理解决跨域问题
前言: 一般跨域问题只要后端配置好的话,是不需要前端做处理的,但也不能保证你遇到的所有后端都能很好的处理这个问题,这个时候可能就需要前端设置代理解决这个问题了. 配置方法: 1. config/ind ...
- django的模板语言中一些之前没有用过的小点
1.模板语言中的for循环的最后一个的表示方式 {% for auther in auther_list %} {% if forloop.last %} {# 这里的意思是for循环的最后一个的意思 ...
- 安装SQLserver2008r2出现 试图执行未经授权的操作
安装时取消对兼容模式的勾选,重新安装就可以了. 或者加上 以管理员身份运行,兼容性设置,以管理员身份运行
- python+selenium环境安装
目前 selenium 版本已经升级到 3.7了,网上的大部分教程是基于 2.x写的,所 以在学习前先要弄清楚版本号,这点非常重要.本系列依然以 selenium2 为基础, 目前 selenium3 ...
- AsnycTask内部实现原理
AsnycTask 原理就是“线程池 + Handler”的组合. 使用线程池的主要原因是避免不必要的创建及销毁线程的开销. AsyncTask 里的线程池: private static final ...
- 利用dom4j读写XML
public static HashMap<String, String> ReadConfig() { HashMap<String, String> map=new Has ...
- xml转化为Dictionary
代码 public SortedDictionary<string, object> FromXml(string xml) { SortedDictionary<string, o ...
- easyrules
http://www.easyrules.org/tutorials/hello-world-tutorial.html
- VSS源代码管理器运行代码分析工具的命令
当你发现代码库总是报需要联系管理员运行代码分析工具时,你可以使用命令分析代码库代码解决: To fix the database problems, you can restart the analy ...
- Android开发之动态设置字体的样式和粗细
字体设置通常有两种形式: 1:在xml中直接设置 android:textStyle="bold" android:typeface="sans" 2:用jav ...