未捕获的TypeError“ vuex__WEBPACK_IMPORTED_MODULE_1__.default.store不是构造函数”

时间:2019-03-21 13:10:13

标签: vue.js vuex

在Vue.js中,我试图使用vuex将数据携带到store.js文件中,但出现错误“ store.js?07a4:6 Uncaught TypeError:vuex__WEBPACK_IMPORTED_MODULE_1__.default.store不是构造函数”。我的代码在下面。

Store.js文件

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

Vue.use(Vuex)

export const store = new Vuex.store({
  state: {
    stocks:[
      {brand: "x", price: 110},
      {brand: "y", price: 200},
      {brand: "z", price: 250},
      {brand: "t", price: 60}
    ],
    stockInfo: {
      stockNumber: "",
      stockPrice: "",
      totalPrice: "",
      brand: ""
    }
  }
})

Main.js文件

import Vue from 'vue'
import VueRouter from 'vue-router'
import VueResource from 'vue-resource'
import App from './App.vue'
import BootstrapVue from 'bootstrap-vue'

import { routes } from './routes.js'
import { store } from './store/store.js'

Vue.use(VueRouter)
Vue.use(VueResource)
Vue.use(BootstrapVue)


import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'

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

Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app')

0 个答案:

没有答案