路由传值分为query(path和query)和params(name和params)。
但params传值页面接收为空。
所以用以下这种:
跳转页,如:tab.vue
const toChat = (id: any) => {
router.push({ name: "Chat", state: { id } })
}
接受页,如:index.vue
const getId = () => {
chatId.value = history.state.id
}
用state传值,跳转之后用history.state.传递的名称即可拿到传递的值。可以很好解决params传值为空的问题。
文章讲述了在Vue中,使用`router.push`时,通过将参数放入`state`对象而非`params`来避免接收页面params值为空的问题,通过`history.state`在目标页面获取传递的值。
2843

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



