js cookie 操作

获取

var GetCookies = () => {
  var n = []
  document.cookie.split(‘;‘).forEach(o => { var x = o.split(‘=‘); n[x[0].trim()] = x[1] })
  return n;
}


//调用
var cookies= GetCookies()
var token = cookies.token 
var token = cookies["token"] 

 

设置

var SetCookie = (key, val, hour) => {

    document.cookie = `${key}=${val}; expires=${new Date(new Date().getTime() + ( hour * 1000 * 60 * 60))}`;
}

 

js cookie 操作

上一篇:使用pxtorem时遇到PostCSS plugin postcss-pxtorem requires PostCSS 8


下一篇:config.json元素含义速查