在尝试导入vuex时,我得到了#34; "未捕获的TypeError:无法读取属性' _lifecycleHooks'未定义"

时间:2017-05-27 19:29:23

标签: javascript vue.js vuejs2 vuex

当我尝试将vuex加载到我的项目中时出现此错误

Uncaught TypeError: Cannot read property '_lifecycleHooks' of undefined
at applyMixin (app.js:17155)
at Object.install (app.js:17812)
at Object.Vue.use (app.js:4274)
at Number.<anonymous> (app.js:130)
at c (app.js:55916)
at w.require (app.js:55916)
at Number.<anonymous> (app.js:56)
at c (app.js:55916)
at Function.r.import (app.js:55916)
at app.js:55913

这是我的store.js文件

import * as Vue from 'vue/dist/vue.common.js'
import * as Vuex from 'vuex'

Vue.use(Vuex);

const store = new Vuex.Store({
    state: {
        pokemons: []
    },
    actions: {
        LOAD_POKEMON_LIST: function() {
            axios.get('http://pokeapi.co/api/v2/pokemon/').then((response) => {
                console.log(response.data)
            }, (err) => {
                console.log(err)
            })
        }
    }
});

export default store

这是我的index.ts

import * as Vue from 'vue/dist/vue.common.js'
import * as Vuex from 'vuex'
import * as axios from 'axios'
import * as App from './components/App.vue'
import * as store from './components/store.js'

Vue.use(Vuex);
Vue.use(axios);

new Vue({
    el: '#app',
    store,
    render: h => h(App),
})

错误在线

_lifecycleHooks.indexOf('init') > -1;

这是错误显示的lop

var applyMixin = function (Vue) {
  var version = Number(Vue.version.split('.')[0]);

  if (version >= 2) {
    var usesInit = Vue.config._lifecycleHooks.indexOf('init') > -1;
    Vue.mixin(usesInit ? { init: vuexInit } : { beforeCreate: vuexInit });
  } else {
    // override init and inject vuex init procedure
    // for 1.x backwards compatibility.
    var _init = Vue.prototype._init;
    Vue.prototype._init = function (options) {
      if ( options === void 0 ) options = {};

      options.init = options.init
        ? [vuexInit].concat(options.init)
        : vuexInit;
      _init.call(this, options);
    };
  }

0 个答案:

没有答案