在 vue-cli vuex 中,使用 this.$store 无法获取存储对象,但使用 this.$store.store 可以

in vue-cli vuex , use this.$store can't get store object, but use this.$store.store it works

that this.$store.state I get a undefined, but use this.$store.store get a correct result

store/index.js

这是export default造成的。尝试直接导出 const.

示例:

store.js

import 'Vue' from 'vue';
import 'Vuex' from 'vuex';

Vue.use(Vuex);

export const store = new Vuex.Store({
  state: {
     //your code here//
  }
});

Main.js

import 'store' from 'wherever the file is/mystore.js';

new Vue({
  el: '#app',
  store, <-- Here is defined store to use along the my app
  render: h => h(App)
});