一些工具方法

getCookie (name) { // 获取cookie
    const cookieContent = '; ' + document.cookie
    const cookies = cookieContent.split(`; ${name}=`)
    return cookies.length - 1 ? cookies.pop().split(';').shift() : ''
 },
setCookie (name, val, days) { // 设置cookie
    let expires = ''
    if (days) {
      const date = new Date()
      date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000))
      expires = `; expires=${date.toUTCString()}`
    }
    document.cookie = `${name}=${val}${expires}; path=/`
},
delCookie (name) {
    var exp = new Date()
    exp.setTime(exp.getTime() - 1)
    var cval = this.getCookie(name)
    if (cval != null) {
      document.cookie = name + '=' + cval + ';expires=' + exp.toGMTString() + ';path=/;domain = .zhaopin.com'
    }
},
//退出系统时调用
deleteSession () {
    const env = process.env.NODE_ENV
    const empId = Common.getCookie('xxx')
    sessionStorage.removeItem(`${env}${empId}leftMenu`)
},
posted @ 2019-03-13 18:56  yangAL  阅读(112)  评论(0编辑  收藏  举报