2016-03-05 76 views
0

新鲜NPM和vuex后同时使用browserify安装,创造新的Vue.store不断抛出calendar_component.js:10205Uncaught TypeError: Cannot read property 'config' of undefined.使用vuejs新vuex店出现了意外配置错误

开放错误显示验证码:

function Store() { 
     var _this = this; 

     var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; 

     var _ref$state = _ref.state; 
     var state = _ref$state === undefined ? {} : _ref$state; 
     var _ref$mutations = _ref.mutations; 
     var mutations = _ref$mutations === undefined ? {} : _ref$mutations; 
     var _ref$modules = _ref.modules; 
     var modules = _ref$modules === undefined ? {} : _ref$modules; 
     var _ref$middlewares = _ref.middlewares; 
     var middlewares = _ref$middlewares === undefined ? [] : _ref$middlewares; 
     var _ref$strict = _ref.strict; 
     var strict = _ref$strict === undefined ? false : _ref$strict; 
     babelHelpers.classCallCheck(this, Store); 

     this._dispatching = false; 
     this._rootMutations = this._mutations = mutations; 
     this._modules = modules; 
     // bind dispatch to self 
     var dispatch = this.dispatch; 
     this.dispatch = function() { 
     for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { 
      args[_key] = arguments[_key]; 
     } 

     dispatch.apply(_this, args); 
     }; 
     // use a Vue instance to store the state tree 
     // suppress warnings just in case the user has added 
     // some funky global mixins 
     var silent = Vue.config.silent; 
     Vue.config.silent = true; 
     this._vm = new Vue({ 
     data: state 
     }); 
     Vue.config.silent = silent; \\---------------> this is the line of the error here\\ 
     this._setupModuleState(state, modules); 
     this._setupModuleMutations(modules); 
     this._setupMiddlewares(middlewares, state); 
     // add extra warnings in strict mode 
     if (strict) { 
     this._setupMutationCheck(); 
     } 
    } 

我不知道为什么会发生这种情况,我试图重新安装,但继续这个错误。这里是我的根vue实例,我试图启动vuex商店。

// browserify entrypoint 

var Vue = require('vue'); 
import Vuex from 'vuex'; 

import calendarHeader from './components/Header.vue'; 
import calendarSettings from './components/Settings.vue'; 
import calendarContent from './components/Contents.vue'; 

const state = { 
    count: 0 
} 

const mutations = { 
    INCREMENT (state) { 
     state.count++ 
    } 
} 

const store = new Vuex.Store({ 
    state, 
    mutations 
}); 

new Vue({ 

    store, 

    el: '#calendar', 

    components: { calendarHeader, calendarSettings, calendarContent}, 

    ready: function() { 

     console.log('Ready too go!'); 
     console.log(store.state.count) // -> 1 
    }, 

    methods: { 

     parallax: function() { 

      var velocity = 0.4; 
      var pos = $('#calendar').scrollTop(); 
      var scr = Math.round((0 - pos) * velocity); 

      $('.current_day_header .header_window').css('backgroundPosition', '0 ' + scr + 'px'); 

       if(scr < -200){ 
        scr = -200; 
       } 
     } 

    } 
}); 

如何解决此错误?所以我删除了一切,并缩小到这一行

const store = new Vuex.Store({ 

有人可以帮我吗?

+0

在文件中说Vue.config.silent是否有var var = require('vue'); – Jeff

回答

0

答案在本教程中隐藏。我正在使用示例部分重新创建商店,但直到他们提到此信息的文档的很晚以后才错过了Vue.use(Vuex)

0
import Vue from 'vue' 
import Vuex from 'vuex' 
import calendarHeader from './components/Header.vue' 
import calendarSettings from './components/Settings.vue' 
import calendarContent from './components/Contents.vue' 

// You have to "install" Vuex 
// http://vuejs.org/api/#Vue-use 
Vue.use(Vuex) 

const state = { 
    count: 0 
} 

const mutations = { 
    INCREMENT(state) { 
     state.count++ 
    } 
} 

const store = new Vuex.Store({ 
    state, 
    mutations 
}); 
相关问题