Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

docs(readme): add instructions for Nuxt Bridge #437

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,47 @@ export default ({ store, req }) => {
};
```

#### Using Nuxt Bridge with cookies (universal client + server-side)

Add `cookie`:

`npm install --save cookie`
or `yarn add cookie`

```typescript
// nuxt.config.ts
...
plugins: ['~/plugins/persistedState.js']
...
```

```typescript
// ~/plugins/persistedState.ts

import { Context } from '@nuxt/types'
import createPersistedState from 'vuex-persistedstate'
import Cookies from 'js-cookie'
import { useCookie } from 'h3'

export default ({ store, req }: Context) => {
createPersistedState({
paths: ['participationData'],
storage: {
getItem: (key) => {
if (process.server) {
return useCookie(req, key)
} else {
return Cookies.get(key)
}
},
setItem: (key, value) =>
Cookies.set(key, value, { expires: 365, secure: true }),
removeItem: (key) => Cookies.remove(key),
},
})(store)
}
```

## API

### `createPersistedState([options])`
Expand Down