获取
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))}`; }