Skip to content

useRouteQuery

Category
Export Size
607 B
Package
@vueuse/router
Last Changed
last month

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

用法

ts
import { useRouteQuery } from '@vueuse/router'

const search = useRouteQuery('search')

const search = useRouteQuery('search', 'foo') // 或者带有默认值

const page = useRouteQuery('page', '1', { transform: Number }) // 或者进行值转换

console.log(search.value) // route.query.search
search.value = 'foobar' // router.replace({ query: { search: 'foobar' } })

类型声明

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

Source

SourceDocs

贡献者

Anthony Fu
丶远方
Antério Vieira
Anthony Fu
Lindsay Gaines
Manoah Tervoort
Shean de Montigny-Desautels
Eduardo Wesley
wheat
Dvir Hazout
Curt Grimes
Sacha STAFYNIAK
reslear
Marshall Thompson

变更日志

v11.0.0-beta.3 on 8/14/2024
965bf - fix(useRouteHash, useRouteParams, useRouteQuery): fix effect triggering multiple times (#4113)
v10.8.0 on 2/20/2024
c44fe - fix(useRouteParams,useRouteQuery): set route param/query to undefined when null or defaultValue (#3583)
v10.6.0 on 11/9/2023
771e7 - fix(useRouteQuery,useRouteParams): prevent reset on other scope dispose (#3418)
v10.3.0 on 7/30/2023
0d02f - fix(router): improves router functions: synchronize values, adds tests, and optimize performance (#3184)
v10.2.0 on 6/16/2023
d5252 - fix(useRouteHash,useRouteQuery,useRouteParams): re-evaluates the value immediately (#3002)
v10.0.0-beta.4 on 4/13/2023
d23ca - feat(useRouteQuery,useRouteParams): new transform handler (#2191)
v9.11.0 on 1/17/2023
07c95 - fix: allow setting multiple route queries in same tick (#2646)

Released under the MIT License.