vue of using cookie

vue repository has a very easy to use plug-vue-cookies

github address: https: //github.com/cmp-cc/vue-cookies

Is also very easy to use, will be introduced vue-cookies.js

$ Cookies.config () to set the default value

$cookies.config(expireTimes, path)

Default 1D expireTimes
path default '/',

$cookies.set()

$cookies.set(key, value[, expireTimes[, path[, domain[, secure]]]]) 
  1. key: cookie名
    注意 $cookies key names Cannot be set to ['expires', 'max-age', 'path', 'domain', 'secure']
  2. value: the cookie value
    vue-cookie will automatically help you put an object into json IF (value && value.constructor === Object) {value = JSON.stringify (value)}
  3. expireTimes: cookie valid time, the default time to 1d
    may point expiration time may be a valid time period, incoming Infinity || -1 is considered in vue-cookies in the cookie permanent incoming '0' is closed when the destruction of the browser cookie
  4. path: the cookie directory, the default '/' root directory
    set path: '/ projectName /' designated project under the name of '/ projectName /' use
  5. domain: the domain where the cookie, the default request address
  6. Secure: Secure attribute is that if a cookie is set Secure = true, then the cookie can only be sent to the server using the https protocol, not http transmission protocol.

$cookies.get('key')

$cookies.get(key)       // return value

$cookies.remove('key')

$cookies.remove(key [, path [, domain]])   // return  false or true , warning: next version return this; use isKey(key) return true/false,please

Is there a key cookie

$cookies.isKey(key) // return true or false

List all cookie

$cookies.keys() // return ['key', 'key', ......]

 

 

Guess you like

Origin www.cnblogs.com/jcydd/p/11488303.html