vue3使用vue-router4.0,但是使用router.push的params传参,一直拿不到参数
查阅资料如下:



——————————————————————————————————————————
state方案如下:
要传参的组件
- import { useRouter } from 'vue-router'
- const router = useRouter() // router跳转
-
- //某个按钮实现路由跳转
- //state里面是参数
- function editor(row) {
- router.push({
- name: 'EditorButton',
- state: {
- description: row.description,
- code: row.code,
- value: row.value
- }
- })
- }
-
- //这个name在router路由配置的时候写过了对应的组件
接受参数的组件:直接用即可
-
- <span >配置项说明span>
- <span>{{ editInfo.description }}span>
-
-
- //拿到路由传过来的数据
- const editInfo = reactive(history.state);
注意:好像只影响 router.push ,用to传参还是可以的
- <router-link
- :to="{ name: 'GameDetail', params: { gameId: row.gameId } }">
- {{ row.gameName }}
- router-link>