当前位置:   article > 正文

cookie设置_设置cookie

设置cookie
  1. /**
  2. * 设置是否登录且未关闭浏览器cookie
  3. */
  4. export const setCookiesIsCloseBrowser = () => {
  5. document.cookie = 'islogin=true'
  6. }
  7. /**
  8. * 获取指定cookie
  9. * @param {cookie} cookieName
  10. * @returns cookie值
  11. */
  12. export const getCookie = (cookieName) => {
  13. const strCookie = document.cookie
  14. const cookieList = strCookie.split(';')
  15. for (let i = 0; i < cookieList.length; i++) {
  16. const arr = cookieList[i].split('=')
  17. if (cookieName === arr[0]) {
  18. return arr[1]
  19. }
  20. }
  21. return ''
  22. }
  23. /**
  24. * 删除指定cookie
  25. * @param {*cookie} cookieName
  26. */
  27. export const deleteCookie = (cookieName) => {
  28. var exp = new Date();
  29. exp.setTime(exp.getTime() - 1);
  30. var cval = getCookie(cookieName);
  31. if (cval != null) document.cookie = cookieName + "=" + cval + ";expires=" + exp.toGMTString();
  32. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/149580
推荐阅读
相关标签
  

闽ICP备14008679号