Vue js:创建的挂钩中出现错误:“ TypeError:无法读取未定义的属性'dispatch'”

时间:2019-12-21 13:54:35

标签: vue.js vuex

我的学习应用程序正在编写的错误以及此错误Error in render: "TypeError: Cannot read property 'getters' of undefined"也被提及,我的代码如下

我确保一切都正确导入,但仍然出现此错误,我在这里遗漏了什么吗?

Main.js

   import Vue from 'vue';
import App from './App.vue';
import VueRouter from 'vue-router';
import { routes } from './routes.js';
import { store } from './store/store.js';

Vue.use(VueRouter);

const router = new VueRouter({
  routes,
  mode: 'history'
});

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

App.vue

<template>
  <div class="container">
    <app-Header></app-Header>
    <router-view></router-view>
  </div>
</template>

<script>
import Header from "./components/Header.vue";
import store from "./store/store.js";
export default {
  created() {
    this.$store.dispatch("initStocks");
  },
  components: {
    appHeader: Header
  }
};
</script>

<style></style>

1 个答案:

答案 0 :(得分:0)

我需要将其从import { store } from './store/store.js';改成import store from './store/store.js';