默认 cookie 是随着浏览器进程关闭而失效,可以在配置文件 中进行修改。如:

    1. timeout: 7 * 24 * 3600 //将 cookie 有效时间设置为 7 天
    2. };

    controller 或者 logic 中,可以通过 this.cookie 方法来获取。如:

    1. export default class extends think.controller.base {
    2. indexAction(){
    3. let cookie = this.cookie('theme'); //获取名为 theme 的 cookie
    4. }

    controller 或者 logic 中,可以通过 this.cookie 方法来设置。如:

    1. export default class extends think.controller.base {
    2. this.cookie('theme', 'default'); //将 cookie theme 值设置为 default
    3. }
    4. }

    http 对象里也提供了 cookie 方法来设置 cookie。如:

    controller 或者 logic 中,可以通过 this.cookie 方法来删除。如:

    1. export default class extends think.controller.base {
    2. indexAction(){
    3. this.cookie('theme', null); //删除名为 theme 的 cookie
    4. }

    http 对象里也提供了 cookie 方法来删除 cookie。如:

    1. http.cookie('theme', null);