W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎勵(lì)
controller 或者 logic 中,可以通過 this.cookie
方法來獲取。如:
export default class extends think.controller.base {
indexAction(){
let cookie = this.cookie("theme"); //獲取名為 theme 的 cookie
}
}
http 對象里也提供了 cookie
方法來獲取 cookie。如:
let cookie = http.cookie("theme");
cookie 默認(rèn)配置如下:
export default {
domain: "",
path: "/",
httponly: false, //是否 http only
secure: false,
timeout: 0 //有效時(shí)間,0 為瀏覽器進(jìn)程,單位為秒
};
默認(rèn) cookie 是隨著瀏覽器進(jìn)程關(guān)閉而失效,可以在配置文件 src/common/config/cookie.js
中進(jìn)行修改。如:
export default {
timeout: 7 * 24 * 3600 //將 cookie 有效時(shí)間設(shè)置為 7 天
};
controller 或者 logic 中,可以通過 this.cookie
方法來設(shè)置。如:
export default class extends think.controller.base {
indexAction(){
this.cookie("theme", "default"); //將 cookie theme 值設(shè)置為 default
}
}
http 對象里也提供了 cookie
方法來設(shè)置 cookie。如:
http.cookie("theme", "default");
如果設(shè)置 cookie 時(shí)想修改一些參數(shù),可以通過第三個(gè)參數(shù)來控制,如:
export default class extends think.controller.base {
indexAction(){
this.cookie("theme", "default", {
timeout: 7 * 24 * 3600 //設(shè)置 cookie 有效期為 7 天
}); //將 cookie theme 值設(shè)置為 default
}
}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: