关于javascript:js-工具库j4tools四

30次阅读

共计 486 个字符,预计需要花费 2 分钟才能阅读完成。

Cookie

应用

import {Cookies} from "j4tools";

const Cookies1 = new Cookies();

设置 cookie

Cookies1.set("A", "1");
Cookies1.set("B", "2");

获取所有 cookie

Cookies1.get(); // {"A":"1","B":"2"}

获取某个 cookie

Cookies1.get("A"); // 1

删除 cookie

// 默认 path:"/"
Cookies1.set("A", "1");
Cookies1.remove("A");

// 如果设置带有 path 属性,那么删除也必须带上 path 属性
Cookies1.set("A", "1", { path: "/static"});
Cookies1.remove("A", { path: "/static"});

更多用法

const Cookies1 = new Cookies({path: "/", expires: 7});
const Cookies2 = new Cookies({
  path: "/static",
  expires: new Date("2022-01-01"),
});

正文完
 0