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
}
浏览器报错如下:
也就意味着 store成功导入了。但是store.state是undefined 没有传过来
同求助
剛看錯了,應該是要改這樣: