如何总结Vue中路由跳转传递参数的多种方法?

更新于
2026-09-25 12:27:42
1阅读来源:SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计442个文字,预计阅读时间需要2分钟。

如何总结Vue中路由跳转传递参数的多种方法?

在日常生活中,路径跳转的参数传递是比较常见的。传递参数的方式主要有三种:

1. 通过动态路由方式

2.在路由配置文件中配置动态路由

3.在跳转时配置动态路由

例如,跳转到详情页时传递参数:

json

{ path: /detail/:id, name: Detail, component: Detail}

日常业务中,路由跳转的同时传递参数是比较常见的,传参的方式有三种:

1)通过动态路由方式

//路由配置文件中 配置动态路由 { path: '/detail/:id', name: 'Detail', component: Detail } //跳转时页面 var id = 1; this.$router.push('/detail/' + id) //跳转后页面获取参数 this.$route.params.id

2)通过query属性传值

//路由配置文件中 { path: '/detail', name: 'Detail', component: Detail } //跳转时页面 this.$router.push({ path: '/detail', query: { name: '张三', id: 1, } }) //跳转后页面获取参数对象 this.$route.query

3)通过params属性传值

//路由配置文件中 { path: '/detail', name: 'Detail', component: Detail } //跳转时页面 this.$router.push({ name: 'Detail', params: { name: '张三', id: 1, } }) //跳转后页面获取参数对象 this.$route.params

总结:

如何总结Vue中路由跳转传递参数的多种方法?

1.动态路由和query属性传值 页面刷新参数不会丢失, params会丢失

2.动态路由一般用来传一个参数时居多(如详情页的id), query、params可以传递一个也可以传递多个参数 。

补充方法:

页面刷新数据不会丢失

methods:{ insurance(id) { //直接调用$router.push 实现携带参数的跳转 this.$router.push({ path: `/particulars/${id}`, }) }

需要对应路由配置如下:

this.$route.params.id

到此这篇关于vue路由跳转传递参数的方式总结的文章就介绍到这了,更多相关vue路由跳转传递参数的三种方式内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!

本文共计442个文字,预计阅读时间需要2分钟。

如何总结Vue中路由跳转传递参数的多种方法?

在日常生活中,路径跳转的参数传递是比较常见的。传递参数的方式主要有三种:

1. 通过动态路由方式

2.在路由配置文件中配置动态路由

3.在跳转时配置动态路由

例如,跳转到详情页时传递参数:

json

{ path: /detail/:id, name: Detail, component: Detail}

日常业务中,路由跳转的同时传递参数是比较常见的,传参的方式有三种:

1)通过动态路由方式

//路由配置文件中 配置动态路由 { path: '/detail/:id', name: 'Detail', component: Detail } //跳转时页面 var id = 1; this.$router.push('/detail/' + id) //跳转后页面获取参数 this.$route.params.id

2)通过query属性传值

//路由配置文件中 { path: '/detail', name: 'Detail', component: Detail } //跳转时页面 this.$router.push({ path: '/detail', query: { name: '张三', id: 1, } }) //跳转后页面获取参数对象 this.$route.query

3)通过params属性传值

//路由配置文件中 { path: '/detail', name: 'Detail', component: Detail } //跳转时页面 this.$router.push({ name: 'Detail', params: { name: '张三', id: 1, } }) //跳转后页面获取参数对象 this.$route.params

总结:

如何总结Vue中路由跳转传递参数的多种方法?

1.动态路由和query属性传值 页面刷新参数不会丢失, params会丢失

2.动态路由一般用来传一个参数时居多(如详情页的id), query、params可以传递一个也可以传递多个参数 。

补充方法:

页面刷新数据不会丢失

methods:{ insurance(id) { //直接调用$router.push 实现携带参数的跳转 this.$router.push({ path: `/particulars/${id}`, }) }

需要对应路由配置如下:

this.$route.params.id

到此这篇关于vue路由跳转传递参数的方式总结的文章就介绍到这了,更多相关vue路由跳转传递参数的三种方式内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!