默认 cookie 是随着浏览器进程关闭而失效,可以在配置文件 中进行修改。如:
export default {
timeout: 7 * 24 * 3600 //将 cookie 有效时间设置为 7 天
};
controller 或者 logic 中,可以通过 this.cookie
方法来获取。如:
indexAction(){
let cookie = this.cookie('theme'); //获取名为 theme 的 cookie
}
controller 或者 logic 中,可以通过 this.cookie
方法来设置。如:
export default class extends think.controller.base {
indexAction(){
this.cookie('theme', 'default'); //将 cookie theme 值设置为 default
}
http 对象里也提供了 cookie
方法来设置 cookie。如:
controller 或者 logic 中,可以通过 this.cookie
方法来删除。如:
export default class extends think.controller.base {
indexAction(){
this.cookie('theme', null); //删除名为 theme 的 cookie
}
}
http 对象里也提供了 cookie
方法来删除 cookie。如: