【问题标题】:Is the any comparability issue with nuxt Auth Module and vuex-persist?nuxt Auth Module 和 vuex-persist 是否存在可比性问题?
【发布时间】:2020-06-15 23:33:51
【问题描述】:

nuxt Auth modulevuex-persist 是否存在兼容问题?

我被这样添加了 vuex-persist。

// Inside - nuxt.config.js
export default {
  plugins: [
    { src: '~/plugins/vuex-persist', ssr: false }
  ]
}

// ~/plugins/vuex-persist.js
import VuexPersistence from 'vuex-persist'

export default ({ store }) => {
  window.onNuxtReady(() => {
    new VuexPersistence({
    /* your options */
    }).plugin(store);
  });
}

但它无法正常工作。

  1. 当我单击登录时,它会执行上一个操作(使用登录 google/other 之前点击过)。
  2. 登录时状态无法保持。

有什么解决办法吗?

【问题讨论】:

    标签: javascript vue.js local-storage vuex nuxt.js


    【解决方案1】:

    是的,@nuxtjs/auth 模块和 vuex-persist 存在一些问题,

    使用这个

    // ~/store/index.js
    import VuexPersistence from 'vuex-persist'
    const vuexLocal = new VuexPersistence({
      storage: window.localStorage
    })
    
    export const plugins = [vuexLocal.plugin]
    

    而不是文档中的这个

    // Inside - nuxt.config.js
    export default {
      plugins: [
        { src: '~/plugins/vuex-persist', ssr: false }
      ]
    }
    
    // ~/plugins/vuex-persist.js
    import VuexPersistence from 'vuex-persist'
    
    export default ({ store }) => {
      window.onNuxtReady(() => {
        new VuexPersistence({
        /* your options */
        }).plugin(store);
      });
    }
    

    或者您可以使用vuex-persistedstate 作为替代。

    【讨论】:

    • 有没有办法使用 multiTabState?
    猜你喜欢
    • 2019-10-07
    • 1970-01-01
    • 1970-01-01
    • 2021-08-15
    • 2021-09-11
    • 2019-11-04
    • 2018-11-23
    • 2021-07-15
    • 1970-01-01
    相关资源
    最近更新 更多