1 Star 3 Fork 0

xiaofei / pinia-persistedstate-plugin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

pinia-persistedstate-plugin

中文 | English

一个为 vue3 准备的和 vuex-persistedstate 类似的 pinia 插件

安装

npm install pinia-persistedstate-plugin

或者

yarn add pinia-persistedstate-plugin

或者

pnpm add pinia-persistedstate-plugin

UMD

<script src="https://unpkg.com/pinia-persistedstate-plugin/dist/pinia-persistedstate-plugin.umd.js"></script>

插件为 window 添加全局变量 PiniaPersistedstatePlugin

使用

main.ts:

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import { createPersistedState } from 'pinia-persistedstate-plugin'
import App from './App.vue'

const app = createApp(App)
const store = createPinia()

store.use(createPersistedState())

app.use(store).mount('#app')

使用 js-cookie

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import { createPersistedState } from 'pinia-persistedstate-plugin'
import App from './App.vue'
import Cookies from 'js-cookie'

const app = createApp(App)
const store = createPinia()

store.use(
  createPersistedState({
    storage: Cookies
  })
)

app.use(store).mount('#app')

选项

export interface Options {
  /**
   * 存储类型,默认为 `window.localStorage`
   *
   * 支持 `js-cookie` `window.localStorage` `window.sessionStorage`
   */
  storage?: Storage | Cookies
  /**
   * 存储的key值前缀,默认为 `pinia`
   */
  key: string
  /**
   * 是否开启日志,默认为 `false`
   */
  logger: boolean
}

授权

MIT 授权。

MIT License Copyright (c) 2021 xiaofei Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

一个为 vue3 准备的和 vuex-persistedstate 类似的 pinia 插件 展开 收起
TypeScript 等 5 种语言
MIT
取消

发行版 (10)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
TypeScript
1
https://gitee.com/l-x-f/pinia-persistedstate-plugin.git
git@gitee.com:l-x-f/pinia-persistedstate-plugin.git
l-x-f
pinia-persistedstate-plugin
pinia-persistedstate-plugin
main

搜索帮助

14c37bed 8189591 565d56ea 8189591