取出cookie中的值得逗号等字符转换

设置cookie:
获取cookie:

setCookie(name, value) {
    console.log(name, value);
    const Days = 3000;
    const exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + '=' + escape(value) + ';expires=' + exp.toUTCString();
  }

  getCookie(name) {
    console.log(name);
    const strCookie = document.cookie;
    const arrCookie = strCookie.split(';');
    // tslint:disable-next-line:prefer-for-of
    for (let i = 0; i < arrCookie.length; i++) {
      const arr = arrCookie[i].split('=');
      console.log(arr);
      if (arr[0].trim() === name) {
        console.log(arr[1]);

        return arr[1];
      }
    }
    return '';
  }

cookie存储不支持逗号等
获取cookie处理
const arr = str.split('%2C'); // %2C 对应的是 ASCII 字符“,”(英文逗号)

你可能感兴趣的:(html)