vue3 useRouter 传递和获取参数方法
传递参数router.push('/index?id=1&name=aaa')// query 参数router.push({path: '/index',// name: 'index',query: {id: 1,name: 'aa'}})// params 参数router.push({n...
传递参数
router.push('/index?id=1&name=aaa')
// query 参数
router.push({
path: '/index',
// name: 'index',
query: {
id: 1,
name: 'aa'
}
})
// params 参数
router.push({
name: 'home',
params: {
id: '1',
name: 'aaa'
}
获取参数
import {useRouter} from 'vue-router'
setup() {
const router = useRouter()
let params = router.currentRoute.value.query // query参数跳转
// let params = router.currentRoute.value.params // params参数跳转
console.log('currentRoute.value:', router.currentRoute.value)
console.log('params:', params)
}
更多推荐
所有评论(0)