js删除cookie #
代码 #
ts
/**
* 清除所有cookie
* @param {string} path 可选. 默认: /
*/
export function clearCookie(path = '/') {
console.log(document.cookie)
// eslint-disable-next-line
const keys = document.cookie.match(/[^ =;]+(?=\=)/g)
if (keys) {
for (let i = keys.length; i--; ) {
document.cookie = `${keys[i]}=0;expires=${new Date(0).toUTCString()};path=${path}`
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14