Skip to content

useRouteParams

类别
导出体积
518 B
依赖包
@vueuse/router
上次更改
7 months ago

对响应式的 route.params 的简写。 Available in the @vueuse/router add-on.

用法

ts
import { 
useRouteParams
} from '@vueuse/router'
const
userId
=
useRouteParams
('userId')
const
userId
=
useRouteParams
('userId', '-1') // 或者带有默认值
const
userId
=
useRouteParams
('page', '1', {
transform
:
Number
}) // 或者进行值转换
console
.
log
(
userId
.
value
) // route.params.userId
userId
.
value
= '100' // router.replace({ params: { userId: '100' } })

类型声明

ts
export declare function 
useRouteParams
(
name
: string,
):
Ref
<null | string | string[]>
export declare function
useRouteParams
<
T
extends
RouteParamValueRaw
=
RouteParamValueRaw
,
K
=
T
,
>(
name
: string,
defaultValue
?:
MaybeRefOrGetter
<
T
>,
options
?:
ReactiveRouteOptionsWithTransform
<
T
,
K
>,
):
Ref
<
K
>

源码

源码文档

贡献者

一纸忘忧
Anthony Fu
Anthony Fu
Antério Vieira
IlyaL
alexchexes
Stefan Vojvodic
Guillaume Chau
jack-allocate
Lindsay Gaines
huiliangShen
Manoah Tervoort
Shean de Montigny-Desautels
Eduardo Wesley
Dvir Hazout
Curt Grimes
DevilTea

更新日志

7432f - feat(types): deprecate MaybeRef and MaybeRefOrGetter in favor of Vue's native (#4636)
bba3f - feat(router): support partial transform (#4426)
59f75 - feat(toValue): deprecate toValue from @vueuse/shared in favor of Vue's native
23fdb - fix(useRouteParams,useRouteQuery): set route param/query to undefined when defaultValue is ref or getter (#3977)
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
65aa0 - feat(router): transform get / set (#4326)
44772 - fix(useRouteParams, useRouteQuery): effect triggers twice with object getter as watch source (#4283)
965bf - fix(useRouteHash, useRouteParams, useRouteQuery): fix effect triggering multiple times (#4113)
4a882 - fix: support optional params (#3934)
c44fe - fix(useRouteParams,useRouteQuery): set route param/query to undefined when null or defaultValue (#3583)
771e7 - fix(useRouteQuery,useRouteParams): prevent reset on other scope dispose (#3418)
0d02f - fix(router): improves router functions: synchronize values, adds tests, and optimize performance (#3184)