vue3路由跳转传参
时间: 2023-08-19 15:06:16 浏览: 123
在Vue3中,可以使用`router.push`方法进行路由跳转并传递参数。有几种方式可以进行参数传递:
1. 使用路径参数(params):
```javascript
router.push({ name: 'user', params: { userId: '123' }})
```
在目标路由中,可以通过`route.params`来获取传递的参数:
```javascript
console.log(route.params.userId);
```
2. 使用查询参数(query):
```javascript
router.push({ path: 'register', query: { userId: '123' }})
```
在目标路由中,可以通过`route.query`来获取传递的参数:
```javascript
console.log(route.query.userId);
```
请注意,以上示例中的`router`和`route`是通过`useRouter`和`useRoute`新增的API获取的。
#### 引用[.reference_title]
- *1* *2* [vue3中使用router路由实现跳转传参](https://blog.csdn.net/SqlloveSyn/article/details/129411036)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [VUE3 跳转传参的三种方式](https://blog.csdn.net/qq_54602808/article/details/119789250)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文