我如何在 Cookie 和 Vue-persist 中将过期时间设置为小时或分钟? Vuex
how do i set expire time to hours or minutes in Cookie and Vue-persist? Vuex
const vuexCookie = new VuexPersist({
restoreState: (key, storage) => Cookies.getJSON(key),
saveState: (key, state, storage) => Cookies.set(key, state, {
expires: 3
}),
modules: ['user'] // only save user module
})
如何将过期对象设置为秒或分钟?
我不明白3是什么意思
如果是数字,expires
表示天。
I do not understand what the 3 means
所以:
Cookies.set(key, state, {
expires: 3
})
表示 cookie 将在 3 天后过期。
How do i set the expires object to seconds or minutes?
你can use a Date
对象:
var inFifteenMinutes = new Date(new Date().getTime() + 15 * 60 * 1000);
Cookies.set('foo', 'bar', {
expires: inFifteenMinutes
});
或设置一天的小数:
var in30Minutes = 1/48;
Cookies.set('foo', 'bar', {
expires: in30Minutes
});
const vuexCookie = new VuexPersist({
restoreState: (key, storage) => Cookies.getJSON(key),
saveState: (key, state, storage) => Cookies.set(key, state, {
expires: 3
}),
modules: ['user'] // only save user module
})
如何将过期对象设置为秒或分钟?
我不明白3是什么意思
如果是数字,expires
表示天。
I do not understand what the 3 means
所以:
Cookies.set(key, state, {
expires: 3
})
表示 cookie 将在 3 天后过期。
How do i set the expires object to seconds or minutes?
你can use a Date
对象:
var inFifteenMinutes = new Date(new Date().getTime() + 15 * 60 * 1000);
Cookies.set('foo', 'bar', {
expires: inFifteenMinutes
});
或设置一天的小数:
var in30Minutes = 1/48;
Cookies.set('foo', 'bar', {
expires: in30Minutes
});