cookieJS_20210621201637.js 708 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. * @Description: cookie封装
  3. * @Author: Napier
  4. * @LastEditors: Napier
  5. * @LastEditorTime:
  6. */
  7. export default {
  8. /**
  9. * @description:设置cookie
  10. * @param {*} value:值
  11. * @param {*} saveDays :保存的时间
  12. * @param {*} cookieName :键名
  13. */
  14. setCookie: function (value, saveDays, cookieName) {
  15. let date = new Date()
  16. date.setTime(date.getTime() + saveDays * 24 * 60 * 60 * 1000)
  17. document.cookie = cookieName + '=' + escape(value) + ';expires=' + date.toGMTString()
  18. },
  19. /**
  20. *
  21. * @param {*} name
  22. * @returns
  23. */
  24. getCookie: function (name) {
  25. var v = window.document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)')
  26. return v ? v[2] : null
  27. }
  28. }