注意:此工具是个鸡肋的存在,没有多大意义。(浏览器可以直接操作,类似于LocalStorage)


/**

* description: 登录页样式文件

* create_time: 2019-01-03

* message: 不接受任何私下吐槽,请当面沟通协调

*/

class Cookie {

  constructor() {

    this.date= new Date();

  }

  // 存入COOKIE

  set (name, value, day) {

    day= day|| 7;

    const valueType = typeof value;

    value= (valueType == 'string')? JSON.stringify(value):value;

    this.date.setTime(this.date.getTime() + 24 * 60 * 60 * 1000 * day);

    window.document.cookie= name+ '=' + value+ ';path=/;expires=' + this.date.toGMTString();

  }

  // 取出COOKIE

  get (name) {

    let v = window.document.cookie.match('(^|;) ?' + name+ '=([^;]*)(;|$)');

    return v ? v[2] : null

  }

  // 删除COOKIE

  del (name) {

    this.date.setTime(this.date.getTime() - 1)

    let val = this.get(name)

    if (val != null) {

      document.cookie= name+ '=' + val + ';expires=' + this.date.toGMTString();

    }

}

}

export default Cookie


用法:
const Cookie = new cookie();
Cookie.set('A','TEST_TOKEN_Ra')



vue工具类之——Cookie操作

相关文章:

  • 2022-12-23
  • 2021-06-22
  • 2021-06-08
  • 2022-12-23
  • 2022-12-23
  • 2021-06-14
  • 2022-12-23
猜你喜欢
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案