Skip to content

Commit 931a397

Browse files
Update README.md
1 parent 5d9a3f9 commit 931a397

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,40 @@
11
# vue-cli-plugin-cookie
22
🍪 Vue CLI 3/4 Plugin for handling browser cookies
3+
4+
### Install
5+
6+
add the cookie plugin with vue-cli or vue-cli UI. `import` and `.use()` will be added to main.js automatically
7+
```sh
8+
vue add cookie
9+
```
10+
11+
### Example Usage
12+
13+
##### Get a cookie
14+
```js
15+
this.$cookie.get('jwt_token')
16+
```
17+
18+
##### Set a cookie
19+
```js
20+
this.$cookie.set('jwt_token', 'cookie_data')
21+
this.$cookie.set('jwt_token', 'cookie_data', { sameSite: 'Lax', expires: '1Y' }) // set SameSite to Lax, Expires to 1 year
22+
this.$cookie.set('jwt_token', 'One year', { expires: '1Y' })
23+
this.$cookie.set('jwt_token', 'One month', { expires: '1M' })
24+
this.$cookie.set('jwt_token', 'One day', { expires: '1D' })
25+
this.$cookie.set('jwt_token', 'One hour', { expires: '1h' })
26+
this.$cookie.set('jwt_token', 'One minutes', { expires: '1m' })
27+
this.$cookie.set('jwt_token', 'One seconds', { expires: '1s' })
28+
```
29+
30+
##### Remove a cookie on the current domain
31+
```js
32+
this.$cookie.remove('jwt_token')
33+
this.$cookie.delete('jwt_token') // alias of remove
34+
this.$cookie.remove('jwt_token', { domain: 'parentdomain.com' }) // remove the parent domain's cookie
35+
```
36+
37+
##### Get all cookies
38+
```js
39+
this.$cookie.getAll()
40+
```

0 commit comments

Comments
 (0)