index.js 709 字节
Newer Older
yma16's avatar
yma16 已提交
1 2 3 4 5 6 7 8
function cookieGet (name) {
    let strcookie = document.cookie // 获取cookie字符串
    let arrcookie = strcookie.split('; ') // 分割
    // 遍历匹配
    for (let i = 0; i < arrcookie.length; i++) {
        let arr = arrcookie[i].split('=')
        if (arr[0] === name) {
            return arr[1]
yma16's avatar
yma16 已提交
9 10
        }
    }
yma16's avatar
yma16 已提交
11
    return ''
yma16's avatar
yma16 已提交
12 13 14
}

// 打印所有cookie
yma16's avatar
yma16 已提交
15 16 17
function cookiePrint () {
    let strcookie = document.cookie // 获取cookie字符串
    let arrcookie = strcookie.split(';') // 分割
yma16's avatar
yma16 已提交
18

yma16's avatar
yma16 已提交
19 20 21 22
    // 遍历匹配
    for (let i = 0; i < arrcookie.length; i++) {
        let arr = arrcookie[i].split('=')
        console.log(arr[0] + '' + arr[1])
yma16's avatar
yma16 已提交
23 24
    }
}
yma16's avatar
yma16 已提交
25
export default { cookieGet, cookiePrint }