在'../store'中找不到“出口'商店'

时间:2017-08-25 15:25:24

标签: vue.js vuex

我想把我的商店导入我的Vuex Route-Gard。

路由器/ AUTH-guard.js

import {store} from '../store'
export default (to, from, next) => {
if (store.getters.user) {
  next()
} else {
next('/login')
}
}

存储/ index.js

import {store} from '../store'
export default (to, from, next) => {
if (store.getters.user) {
  next()
 } else {
 next('/login')
 }
}

我得到的错误     在'../ store'中找不到导出'商店'

我的vue设置

"dependencies": {
"firebase": "^4.3.0",
"vue": "^2.3.3",
"vue-router": "^2.6.0",
"vuex": "^2.3.1"

1 个答案:

答案 0 :(得分:1)

我能够通过这种方法解决这个问题。

main.js

import {store} from './store'
new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: {
    App
  },

auth-guard.js

import {store} from '../store'
export default (to, from, next) => {
if (store.getters.user) {
  next()
 } else {
 next('/login')
}
}

store/index.js

Vue.use(Vuex)
export const store = new Vuex.Store({
modules: {
products,
bids,
user
}
})