vuex store传递出错问题

main.js代码如下:

// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import VueRouter from 'vue-router'
import store from './store'
import App from './App'
import Icons from './components/Icons.vue'

Vue.use(VueRouter);

const routes = [
  { path: '', component: Icons },
  // { path: '/bar', component: Bar }
]
const router = new VueRouter({
  routes // (缩写)相当于 routes: routes
})

const icons = new Vue({
  router
}).$mount('#icons-bar')


/* eslint-disable no-new */
var app = new Vue({
  el: '#app',
  template: '<App/>',
  components: { App }
})

var position = new Vue({
  el: '#position',
  computed: {
    show() {
      console.log(store.state);
      return store.state.hide;
    }
  },
  methods: {
    increment () {
      store.commit('increment')
    }
  }
})

var motto = new Vue({
  el: '#motto',
  data: {
    show:false,
    motto:'"我怎能轻易倒下,我的背后空无一人"'
  }
})

exports.position = position;
exports.motto = motto;

store.js代码如下:

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

Vue.use(Vuex);



const store = new Vuex.Store({
  state: {
    hide: true
  },
  mutations: {
      increment: state => !state.hide,
  }
})

console.log("hah"+store.state.hide);


module.exports = {
  store: store
}

浏览器报错如下:

clipboard.png
也就意味着 store成功导入了。但是store.state是undefined 没有传过来
同求助

阅读 4.1k
1 个回答

剛看錯了,應該是要改這樣:

module.exports = store
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题