When p-cookie is used in apps, apps can support cookies

1. Install app-cookie

npm install weapp-cookie --save
Copy the code

2. Introduce appellate P-cookie

Post-symptomatic P-cookie is added, which automatically proxy the underlying INTERFACE of WX. request for access to support cookie storage and sending

//app.js
//import cookies from 'weapp-cookie'
import './miniprogram_npm/weapp-cookie/index'
Copy the code

3, API

import cookies from 'weapp-cookie'

/** * get the cookie value *@param {String} Name Cookie name *@param {String} [domain] Specify the domain name (optional) *@return {String}           The cookie value * /
cookies.get(String name, String domain)
 
/** * Set cookie *@param {String}  Name Cookie name *@param {String}  The value the cookie value *@param {Object}  Options Cookie options *@param {String}  Options. domain Sets the domain name *@param {String}  [options.path]      
* @param {Date}    [options.expires] 
* @param {Number}  [options.maxAge] 
* @param {Boolean} [options.httpOnly] 
* @return {Cookie}           Cookie object * /
cookies.set(String name, String value, Object options)
 
/** * Whether a cookie exists *@param  {String}  Name Cookie name *@param  {String}  [domain] Specify the domain name (optional. If no domain name is specified, any domain name that contains cokkie name exists) *@return {Boolean}            Whether */ exists
cookies.has(String name, String domain)
 
/** * delete cookie *@param  {Array}  * the name cookie key@param  {String} [domain] Specify the domain name (optional. If this parameter is not specified, cookies with name in all domain names will be deleted) *@return {Boolean}          Check whether the file is successfully deleted */
cookies.remove(String name, String domain)
 
/** * get cookie object *@param {String} Name Cookie name *@param {String} [domain] Specify the domain name (optional) *@return {Cookie}           Cookie object * /
cookies.getCookie(String name, String domain)
 
/** * Get cookies JSON object *@param  {String} [domain] Specifies the domain name (optional, if this parameter is not specified, the cookie value object containing all domain names is obtained) *@return {Object}           Cookie JSON object */
cookies.getCookies(String domain)
 
/** * Get cookies Array *@param  {String} [domain] Specifies the domain name (optional, if this is not specified, the cookie array containing all domain names is obtained) *@return {Array}            Cookie object array */
cookies.getCookiesArray(String domain)
 
/** * Batch set cookie *@param  {Array} Cookies Cookie object array *@return {Map}            Cookies Map object */
cookies.setCookiesArray (Array cookies)
 
/** * clear cookies *@param  {String} [domain] Specifies the domain name (optional. If this parameter is not specified, cookies are cleared) *@return {Boolean}          Check whether the file is cleared successfully */
cookies.clearCookies (domain)
 
/** * Get all stored domain names and cookies structures *@return {Object}   Obj structure JSON object */
cookies.dir(domain)
Copy the code