【问题标题】:vuex duplicate namespace auth/ for the namespaced module authvuex 重复命名空间 auth/ 用于命名空间模块 auth
【发布时间】:2020-05-07 07:21:26
【问题描述】:

我将 nuxt.js 与 auth 模块一起使用。 每次我在个人资料上打开新页面时,都会出现此错误消息。 我在我的 plugins/mixins 目录中创建了一个名为 auth.js 的 mixin。此文件包含代码:

export const getters = {
    authenticated(state) {
        return state.loggedIn;
    },

    user(state){
        return state.user;
    }
};

我使用以下代码创建了一个名为 auth.js 的 getter 文件:

import Vue from 'vue'
import {mapGetters} from 'vuex'

const User = {
    install(Vue, options) {
        Vue.mixin({
            computed: {
                ...mapGetters({
                    user: 'auth/user',
                    authenticated: 'auth/authenticated'
                })
            }
        })
    }
};

Vue.use(User);

getter 和 mixin 可以工作,但每次我打开一个页面时,它都会给我这个错误,我不知道如何解决它。我已经尝试过这个问题的解决方案: duplicate namespace auth/ for the namespaced module auth 尽管这确实解决了错误,但它使我的吸气剂未定义。

【问题讨论】:

    标签: vuex nuxt.js mixins getter vuex-modules


    【解决方案1】:

    是的,我找到了一种可行的方法...... 切换到index.js auth.js 逻辑,删除auth.js。

    index.js

    export const getters = {
    authenticated(state) {
      return state.auth.loggedIn
    },
    
    user(state) {
      return state.auth.user
    }
    }
    

    如果你使用的是 user.js mixin,修改如下:

    import Vue from 'vue'
    import {mapGetters} from 'vuex'
    
    const User = {
        install(Vue, options) {
            Vue.mixin({
                computed: {
                    ...mapGetters({
                        user: 'user',
                        authenticated: 'authenticated'
                    })
                }
            })
        }
    };
    
    Vue.use(User);
    

    插件:

    ** Plugins to load before mounting the App
    */
    plugins: ["./plugins/mixins/user.js"
    ],
    

    【讨论】:

      猜你喜欢
      • 2020-07-14
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 2018-12-31
      • 1970-01-01
      • 2020-04-07
      • 2014-11-28
      • 2020-09-27
      相关资源
      最近更新 更多