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 ( ";" ) ) ;
//console.log(this.string);
let idx = this . string . indexOf ( "=" ) ;
this . key = this . string . slice ( 0 , idx ) ;
this . value = this . string . slice ( idx + 1 ) ;
//console.log(this);
}
toString ( ) {
return this . string ;
//return this.key + "=" + this.value;
}
save ( ) {
if ( ! this . key ) {
throw new Error ( "没有键值" ) ;
}
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();