> For the complete documentation index, see [llms.txt](https://guygubaby.gitbook.io/vue/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guygubaby.gitbook.io/vue/master.md).

# vue utils

## vuex persisted

vuex数据持久化，刷新页面的时候不会数据丢失

{% embed url="<https://www.npmjs.com/package/vuex-persistedstate>" %}

## usage

vuex index.js

```javascript
import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

export default new Vuex.Store({
  plugins: [createPersistedState({ storage: window.sessionStorage })], // 添加持久化state插件
  state: {
    count: 0
  }
})
```

可以在App.vue 的created里面进行恢复数据(比如恢复http请求头之类的)
