Handling Cookies In Vue.js – vue-cookies

Install & Download:

# NPM
$ npm i vue-cookies --save

Description:

A simple Vue.js 3/2 plugin for handling and managing browser cookies.

How to use it:

1. Import and register the plugin.

import Vue from 'vue'
import VueCookies from 'vue-cookies'
Vue.use(VueCookies, { 
  // options here
})

2. Available options.

{ 
  expires: '1d', 
  path: '/', 
  domain: '', 
  secure: '', 
  sameSite: 'Lax' 
}

3. Cookie operations.

// Set a cookie
$cookies.set(keyName, value[, expires[, path[, domain[, secure[, sameSite]]]]])
// Get a cookie
$cookies.get(keyName)
// Remove a cookie
$cookies.remove(keyName [, path [, domain]])
// Exist a cookie name
$cookies.isKey(keyName)
// Get All cookie name
$cookies.keys()

Preview:

vue-cookies

Changelog:

03/02/2023

  • v1.8.3: update

10/29/2022

  • v1.8.2: update

04/27/2022

  • v1.8.1: declare vue3 options api

04/10/2022

  • v1.8.0

04/07/2022

  • Support Vue 3
Tags:

Add Comment