1、this.$route.query:
(1) 传参:
this.$router.push({
path: '/xxx',
query:{
id:id
}
})
(2) 获取参数:
this.$route.query.id
(3) 在 url 中形式(url 中带参数):
http://xxx?id=1,刷新跳转后传参的页面,数据还会存在
2、this.$route.params:
(1) 传参:
this.$router.push({
name: 'xxx',
params:{
id:id
}
})
(2) 获取参数:
this.$route.params.id
(3) 在 url 中形式(url 中不带参数):
http://xxx,刷新跳转后传参的页面,数据不存在
Vue与后端交互:$route和$router参数详解
本文详细解析了Vue中如何使用$route.query和$router.params进行参数传递与获取,分别介绍了在URL中的展示方式以及刷新后数据保持情况。重点讲解了两种方式在前端路由中的应用和区别。
1万+

被折叠的 条评论
为什么被折叠?



