Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/leandromatos/nuxt-cookie
The Cookie Module for Nuxt, works perfectly on the client side and on the server side for set, get and remove cookies.
https://github.com/leandromatos/nuxt-cookie
cookie javascript nuxt nuxt-module nuxtjs
Last synced: 18 days ago
JSON representation
The Cookie Module for Nuxt, works perfectly on the client side and on the server side for set, get and remove cookies.
- Host: GitHub
- URL: https://github.com/leandromatos/nuxt-cookie
- Owner: leandromatos
- License: mit
- Created: 2020-11-04T17:37:48.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-11-04T18:06:24.000Z (about 4 years ago)
- Last Synced: 2024-12-09T02:07:14.216Z (29 days ago)
- Topics: cookie, javascript, nuxt, nuxt-module, nuxtjs
- Language: JavaScript
- Homepage:
- Size: 221 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# 🍪 Nuxt Cookie
> The Cookie Module for [Nuxt](https://nuxtjs.org/), works perfectly on the client side and on the server side for set, get and remove cookies.
[📖 **Release Notes**](./CHANGELOG.md)
## Setup
Add `@leandromatos/nuxt-cookie` dependency to your project.
```bash
yarn add @leandromatos/nuxt-cookie
```or
```bash
npm install @leandromatos/nuxt-cookie
```Add `@leandromatos/nuxt-cookie` to the `modules` section of `nuxt.config.js`.
```js
{
modules: ['@leandromatos/nuxt-cookie']
}
```## Usage
After add the module on your project, you can access it through the `$cookie`.
### Set a cookie
`$cookie.set(name, value, options)`
- `name` (string): Cookie name.
- `value` (string orobject|array|boolean): Cookie value.
- `options` (object): Same options as the [cookie.serialize](https://github.com/jshttp/cookie#cookieserializename-value-options) method of the [cookie module](https://github.com/jshttp/cookie).Usage on server-side:
```js
// Nuxt middleware
export default ({ app: { $cookie } }) => {
$cookie.set('cookie-name', 'server-cookie-value', {
path: '/',
})
})
```Usage on client-side:
```js
// Vue component
export default {
mounted() {
this.$cookie.set('cookie-name', 'client-cookie-value', {
path: '/',
})
}
}
```### Get a cookie
`get(name)`
- `name` (string): Cookie name.
```js
// Nuxt middleware
export default ({ app: { $cookie } }) => {
const cookie = $cookies.get('cookie-name')
}
``````js
// Vue component
export default {
mounted() {
const cookie = this.$cookie.get('cookie-name')
}
}
```### Remove a cookie
`remove(name, options)`
- `name` (string): Cookie name.
- `options` (object): Same options as the [cookie.serialize](https://github.com/jshttp/cookie#cookieserializename-value-options) method of the cookie module```js
// Nuxt middleware
export default ({ app: { $cookie } }) => {
const cookie = $cookies.remove('cookie-name')
}
``````js
// Vue component
export default {
mounted() {
const cookie = this.$cookie.remove('cookie-name')
}
}
```## Development
- Clone this repository
- Install dependencies using `yarn install` or `npm install`
- Start development server using `yarn run dev` or `npm run dev`## License
[MIT License](./LICENSE)
Copyright (c) Leandro Matos