Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/vuebits/cookies

Vue 3 library for cookie management
https://github.com/vuebits/cookies

Last synced: 20 days ago
JSON representation

Vue 3 library for cookie management

Awesome Lists containing this project

README

        

Vuebits cookies

*** Maintainers & Contributors welcome ***

Vue 3 library for cookies management

---

## Table of Contents

* [Installation](#installation)
* [API](#api)
* [Documentation](#documentation)

## Installation

`npm i @vuebits/cookies` / `yarn add @vuebits/cookies`

And install in your entry file (e.g. `main.js`):

```javascript
import { createCookies } from '@vuebits/cookies';

createApp(App).use(createCookies({ /* your config here */ })).mount('#app');
```

## API

### Available functions:

* `createCookies (options: CookiesConfig)`:

```ts
interface CookiesConfig {
expireTimes?: string | number | Date;
path?: string;
domain?: string;
secure?: boolean;
sameSite?: string;
}
```

### Vue instance properties and methods:

* `$cookies: Cookies`:

```ts
interface Cookies {
config(config: CookiesConfig): void;
set(keyName: string,
value: any,
expireTimes?: string | number | Date,
path?: string,
domain?: string,
secure?: boolean,
sameSite?: string): this;
get(keyName: string): any;
remove(keyName: string, path?: string, domain?: string): boolean;
isKey(keyName: string): boolean;
keys(): string[];
}
```

### Examples

```vue



Set cookie "test"


Get cookie "test"


Remove cookie "test"


cookie "test": {{ cookie }}

import { defineComponent } from 'vue';

export default defineComponent({
name: 'App',
data () {
return {
cookie: null as any
};
},
methods: {
setCookie (): void {
this.$cookies.set('test', 123);
},
getCookie (): void {
this.cookie = this.$cookies.get('test');
},
removeCookie (): void {
this.$cookies.remove('test');
}
}
});

```