跳转到内容

useUrlState ​

通过 url query 来管理 state 的 Hook。

安装 ​

bash
npm i @vue-hooks-plus/use-url-state

代码演示 ​

API ​

typescript
const state = useUrlState(defaultState, {
  localStorageKey: 'localStorageKey',
  routerPushFn,
})

interface UseUrlStateOptions {
  localStorageKey?: string
}

Params ​

参数说明类型默认值
initialState默认值S | () => S-
options设置localStorageKey的话,若 url 没有参数,会使用存在 localStorage 的值UseUrlStateOptions-
routerPushFn一般来说,传 vue-router 的 router.push方法就行function-

Result ​

参数说明类型
state状态值-

Source ​

源码 · 文档 · 示例

基于 MIT 许可发布