You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
/**
* Cookie类, 用于网络中cookie的各类操作
*/
export class Cookie {
/**
*
* example: "autologin_trustie=8acaa2b09d5056c0e9d82519052276b9d4a524e9; domain=.educoder.net ; path=/; expires=Fri, 29 Nov 2019 15:32:53 -0000; HttpOnly"
*/
constructor ( str ) {
this . origin _str = str ;
this . analyse _cookie ( str ) ;
}
analyse _cookie ( str ) {
this . string = str . slice ( 0 , str . indexOf ( ";" ) ) ;
let idx = this . string . indexOf ( "=" ) ;
this . key = this . string . slice ( 0 , idx ) ;
this . value = this . string . slice ( idx + 1 ) ;
}
toString ( ) {
return this . string ;
//return this.key + "=" + this.value;
}
save ( ) {
if ( ! this . key ) {
console . error ( "cookie保存时: 没有键值key" ) ;
}
wx . setStorageSync ( this . key , this . origin _str ) ;
}
static load ( key ) {
return new Cookie ( wx . getStorageSync ( key ) ) ;
}
}
function test ( ) {
//used to test the class Cookie
cookie _str = "autologin_trustie=8acaa2b09d5056c0e9d82519052276b9d4a524e9; domain=.educoder.net ; path=/; expires=Fri, 29 Nov 2019 15:32:53 -0000; HttpOnly" ;
cookie = new Cookie ( cookie _str ) ;
}
//test();