Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Vuex插件错误_Javascript_Vue.js_Vuejs2_Vuex - Fatal编程技术网

Javascript Vuex插件错误

Javascript Vuex插件错误,javascript,vue.js,vuejs2,vuex,Javascript,Vue.js,Vuejs2,Vuex,我已经包括了“vuex persistedstate.js”,但它在控制台中显示了错误: const store = new Vuex.Store({ state: { user: { userName:'', loggedInStatus: true, authToken: '' } }, mutations: { addWebToken: func

我已经包括了“vuex persistedstate.js”,但它在控制台中显示了错误:

const store = new Vuex.Store({
    state: {
        user: {
            userName:'',
            loggedInStatus: true,
            authToken: ''
        }
    },

    mutations: {
        addWebToken: function(state, webToken){
            state.user.authToken = webToken;
        },
        removeWebToken: function(state){
            state.user.authToken = '';
        }
    },
    methods:{
        getToken:function (){
            return  store.state.user.authToken;

        }
    },
    plugins: [createPersistedState()]

})

当我按住ctrl键并单击createPersistedState()调用时,我可以导航到该文件。

vuex-persistedstate.js需要依赖于lodash和对象路径。这 vuex-persistedstate.js第17行上的错误是缺少lodash依赖项。 如果已添加lodash,请确保已将其加载到vuex persistedstate模块中

如果你真的想使用纯js。您必须使用正确的节点模块定义
window.merge=..merge
window.objectPath
。您宁愿使用webpack来正确使用此npm模块


更多来源:

您是否尝试在没有扩展名
.js的情况下包含它。我不确定这会有什么不同,但我假设如果模块位于节点模块内,那么从“vuex persistedstate”执行
导入createPersistedState
应该包括它的
index.js
文件,而不是它试图加载的任何文件。这可能也解释了为什么没有定义
createPersistedState
-它可能找不到它,因为它在寻找错误的东西。我没有使用节点npm。我使用的是纯js。我不确定,但我觉得这个插件是用npm构建的。如果你看一下,我觉得它是为了在支持导入/需求的框架中使用而构建的。看第12-15行。
Uncaught TypeError: Cannot use 'in' operator to search for 'default' in undefined
  at vuex-persistedstate.js:17

Uncaught ReferenceError: createPersistedState is not defined