The installation

bower

$ bower install cookiejs
Copy the code

npm

$ npm install cookiejs
Copy the code

cookie APIs

Cookie ("test","tank",1800) // Set the value of cookie, survival time half an hour cookie("test") // get the value of cookie, Display tank cookie("test",null) // Delete cookie test cookie() // Empty cookie cookie.set("test","tank",1800) //====cookie("test","tank",1800) cookie.get("test") //====cookie("test") cookie.remove("test") //====cookie("test",null) Cookie.clear () //====cookie() cookie.all() // Get all cookiesCopy the code

Set cookie values in batches

cookie.set({
   name1: 'value1',
   name2: 'value2'
});Copy the code

set

Set the value of cookie and set the time

Cookie. set(name,value,options) has the same effect

Cookie ("test","tank",30) // Set cookie and expire in 30 days Cookie ("test","123",{// Set cookie and expire in 7 days, path, field "Expires ": 7, "path": '/', "domain":"" }); Cookies ({" test ", "123", "test2" : "456"}, {/ / batch set "expires" : 7, "path" : '/', "domain" : ""});Copy the code

get

Gets the value of the cookie

Cookie. get(name) has the same effect cookie(name)

Store ("wcj1") // Get the string data of wcj1. Store ("wcj1") // Same as aboveCopy the code

clear

Clear the cookies

Cookie.clear () has the same effect

remove

Delete the cookie

Cookie. remove(name) same effect Cookie (name,null)

Cookie. remove("test") // delete cookie test cookie("test",null) // Delete cookie testCopy the code

Expires Time, PATH Path, Domain domain, and Secure.

cookie("test","123",{
    "expires": 7,
    "path": '/',
    "domain":""
});
cookie({"test":"123"},{
    "expires": 7,
    "path": '/',
    "domain":""
});Copy the code