Vue.js Vuejs和vuex,无法读取属性'$商店';

Vue.js Vuejs和vuex,无法读取属性'$商店';,vue.js,vuex,Vue.js,Vuex,我正在尝试读取/访问我的vuex存储,但出现错误“无法读取未定义的属性“$store”,为什么 这就是我尝试过的 我在一个单独的store.js文件中创建了一个Vuex存储 import Vuex from "vuex"; import Vue from "vue"; import { Auth } from "aws-amplify"; Vue.use(Vuex); export const store = new Vuex.Sto

我正在尝试读取/访问我的vuex存储,但出现错误“无法读取未定义的属性“$store”,为什么

这就是我尝试过的

我在一个单独的store.js文件中创建了一个Vuex存储

import Vuex from "vuex";
import Vue from "vue";
import { Auth } from "aws-amplify";

Vue.use(Vuex);
export const store = new Vuex.Store({
  state: {
    user: null
  },

  actions: {
    // AWS signup action.
    async signUp({ commit }, { username, password, firstName, lastName }) {
      const data = await Auth.signUp({
        username,
        password,
        attributes: {
          given_name: firstName,
          family_name: lastName
        }
      });
      console.log(data);
    }
  }
});
接下来,我在我的main.jsVue实例中注册了它

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

// Provide an initial state object for Vuex.
import store from './util/store.js';
Vue.use(Vuex)

/* eslint-disable no-new */
new Vue({
  el: '#app',
  store: store, // Vuex mechanism to "inject" the store into all child components from the root component.
  render: h => h(App),
  router
})

我尝试访问商店ie.console.log(this.$store)您错过了导出默认值的
商店:

export default new Vuex.Store({
   ...

并在创建存储时使用
Vue.use(Vuex)
一次,因为
Vue.use(Vuex)
要求您在此之后定义一个存储实例,而在
main.js
中不是这样,它忽略了已经创建的存储。

您在哪里调用了
this.$store
?在我的reg.Vue中,在console.log(this.$store)方法内部请共享整个代码,包括
console.log(此.$store)
@boussadjrarahim updated
export default new Vuex.Store({
   ...