Vuejs2 在vue cli vuex中,使用此选项。$store can';无法获取存储对象,但请使用它。$store.store它可以工作

Vuejs2 在vue cli vuex中,使用此选项。$store can';无法获取存储对象,但请使用它。$store.store它可以工作,vuejs2,vuex,Vuejs2,Vuex,这是由导出默认值引起的。尝试直接导出常量 例如: store.js import 'Vue' from 'vue'; import 'Vuex' from 'vuex'; Vue.use(Vuex); export const store = new Vuex.Store({ state: { //your code here// } }); import 'store' from 'wherever the file is/mystore.js'; new Vue({


这是由导出默认值引起的。尝试直接导出常量

例如:

store.js

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

Vue.use(Vuex);

export const store = new Vuex.Store({
  state: {
     //your code here//
  }
});
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)
});
Main.js

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

Vue.use(Vuex);

export const store = new Vuex.Store({
  state: {
     //your code here//
  }
});
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)
});
从文件所在的位置/mystore.js'导入'store';
新Vue({
el:“#应用程序”,
商店,h(应用程序)
});

它很管用,非常感谢你的帮助,它解决了我几天的难题,但我仍然感到困惑,因为当我使用
导出默认值
时,它会出错,如果使用必须使用
导出默认值
那么如何编写它得到它,如果我使用
导出{store}
,那就好了,我应该仔细阅读es6模块,再次感谢你给我指路,