【发布时间】:2018-11-17 05:59:11
【问题描述】:
我习惯于在 Vuex 中使用 localStorage,但正如你所知,在 SSR 上我们不能使用 localeStorage。所以我搜索了一个解决方案,让 Vuex state 保持页面刷新并多次使用 js-cookie 遇到 vuex-persistedstate。
我的问题是我真的需要vuex-persistedstate 吗?我的意思是我可以像下面这样使用js-cookie:
import Cookie from 'js-cookie'
const state = {
firstName: Cookie.get('firstName)
}
const mutations = {
setFirstName(state, name) {
state.firstName = name;
Cookie.set('firstName', name)
}
等等
【问题讨论】:
-
我在 nuxt 中使用 cookie,而我从未使用过 vuex-persistedstate。甚至从未听说过。我使用 'js-cookie' 来设置 cookie 和 'cookie' 来获取它们。就像我学到的一样。
-
@Andrew1325 所以我可以像上面的例子一样使用?