vue3路由参数params弃用

782 阅读1分钟

以前写的功能突然出问题了
打印route.params 总是为空 原来是弃用了params参数

方法1: 使用 History API 方式传递和接收

在跳转前的页面使用 state 参数:

import { useRouter } from 'vue-router'
 
const router = useRouter()

const params = { id: '1', name: 'ly', phone: 13246566476, age: 23 }
const toDetail = () => router.push({ name: 'detail', state: { params } })

跳转的后页面用history接收:

const historyParams = history.state.params
console.log('history.state', history.state)

www.cnblogs.com/liao-yi/art… github.com/vuejs/route…