简体   繁体   English

使用 npm store.js package 在 cookie 上设置过期日期

[英]Set expire date on cookie with npm store.js package

I'm using " store " to handle my cookies, It all works great, except that I can't figure out how to set an expire date, I'd like to set it for one day我正在使用“商店”来处理我的 cookies,一切都很好,除了我不知道如何设置过期日期,我想设置一天

I've tried following the docs but it doesn't seem to work我试过关注文档,但它似乎不起作用

I imported and set the store like the documentation said:我像文档中所说的那样导入并设置了商店:

var storages = [
    require('store/storages/localStorage'),
    require('store/storages/cookieStorage')
]
var plugins = [
    require('store/plugins/defaults'),
    require('store/plugins/expire')
]
var store = engine.createStore(storages, plugins) 

let expire_date = new Date().getTime() + 86400000;
store.set('livePreview', true, expire_date);

EDIT : I have also tried this:编辑:我也试过这个:

import store from 'store'
var expirePlugin = require('store/plugins/expire')
store.addPlugin(expirePlugin)

let expire_date = new Date().getTime() + 86400000;
store.set('livePreview', true, expire_date); 

Any ideas?有任何想法吗?

Remove this line require('store/storages/localStorage') or move it after the cookie plugin.删除此行require('store/storages/localStorage')或将其移动到 cookie 插件之后。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM