Category | Browser |
---|---|
Export Size | 1.59 kB |
Last Changed | 8 months ago |
Reactive URLSearchParams
import { useUrlSearchParams } from '@vueuse/core' const params = useUrlSearchParams('history') console.log(params.foo) // 'bar' params.foo = 'bar' params.vueuse = 'awesome' // url updated to `?foo=bar&vueuse=awesome`
When using with hash mode route, specify the mode
to hash
import { useUrlSearchParams } from '@vueuse/core' const params = useUrlSearchParams('hash') params.foo = 'bar' params.vueuse = 'awesome' // url updated to `#/your/route?foo=bar&vueuse=awesome`
When using with history mode route, but want to use hash as params, specify the mode
to hash-params
import { useUrlSearchParams } from '@vueuse/core' const params = useUrlSearchParams('hash-params') params.foo = 'bar' params.vueuse = 'awesome' // url updated to `/your/route#foo=bar&vueuse=awesome`
export type UrlParams = Record<string, string[] | string> export interface UseUrlSearchParamsOptions<T> extends ConfigurableWindow { /** * @default true */ removeNullishValues?: boolean /** * @default false */ removeFalsyValues?: boolean /** * @default {} */ initialValue?: T /** * Write back to `window.history` automatically * * @default true */ write?: boolean } /** * Reactive URLSearchParams * * @see https://vueuse.org/useUrlSearchParams * @param mode * @param options */ export declare function useUrlSearchParams< T extends Record<string, any> = UrlParams >( mode?: "history" | "hash" | "hash-params", options?: UseUrlSearchParamsOptions<T> ): T
© 2019-present Anthony Fu
Licensed under the MIT License.
https://vueuse.org/core/useUrlSearchParams/