赞
踩
this.$router.push传递参数有2种方式:
传递参数 -- this.$router.push({path: ' 路由 ', query: {key: value}})
参数取值 -- this.$route.query.key
使用这种方式,传递参数会拼接在路由后面,出现在地址栏.
传递参数 -- this.$router.push({name: ' 路由的name ', params: {key: value}})
参数取值 -- this.$route.params.key
使用这种方式,参数不会拼接在路由后面,地址栏上看不到参数..
动态路由也是传递params的,所以在 this.$router.push() 方法中 path不能和params一起使用,否则params将无效。需要用name来指定页面。
[通过路由配置的name属性访问].
相关文档:VueRouter文档
=====================================================================================================
执行点击按钮跳转页面之前还会执行一系列方法,这时可以使用 this.$router.push(location) 来修改 url,完成跳转
- // 字符串
- this.$router.push('/viewAgent')
- // 对象
- this.$router.push({ path: '/viewAgent' })
- // 命名的路由
- this.$router.push({ name: 'viewAgent', params: { isShow: true}})
跳转页面并传递参数的方法:
1.Params 传值 接收参数
由于动态路由也是传递params的,所以在 this.$router.push() 方法中path不能和params一起使用,否则params将无效。需要用name来指定页面。及通过路由配置的name属性访问
在路由配置文件中定义参数:
-
- /* router.js 文件*/
- import Vue from "vue";
- import Router from "vue-router";
- import MediaSecond from "@/views/EnterprisePage/MediaMatrix/second"; //资讯列表
-
- Vue.use(Router);
- export default new Router({
- routes: [ /* 进行路由配置 */
- {
- name: "MediaSecond",
- path: "/MediaSecond",
- component: MediaSecond
- },
- ]
通过name获取页面,传递params:
- this.$router.push(
- { name: 'MediaSecond',params:{artistName:artistName,imgUrl:imgUrl,type:2}
- })
在目标页面通过this.$route.params获取参数:
- this.$route.params.type
- this.$route.params.artistName
- this.$route.params.imgUrl
2.query 传值 接收参数
页面通过path/name和query传递参数
- this.$router.push({ name: 'DetailManagement', query: { auditID: "row.id", type: '2' } });
- this.$router.push({ path: '/DetailManagement', query: { auditID: "row.id", type: '2' } });
在目标页面通过this.$route.query获取参数:
- this.$route.query.auditID
- this.$route.query.type
3. 通过跳转打开新的标签页并定位到对应页面
- let routeUrl = this.$router.resolve({
- path: '/viewAgent', // 对应路由
- query: { isShow: false } //传值
- })
- window.open(routeUrl.href, '_blank')
接收参数
this.$route.query.isShow
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。