使用vuecli创建的项目 改动了store的路径 npm run serve报错
index.js
import Vue from 'vue';
import Vuex from 'vuex';
import login from "./login";
Vue.use(Vuex)
const state = {};
const getters = {};
const mutations = {};
const actions = {};
const modules = {
login: login
}
export default new Vuex.Store({
//全部组件化
state,
getters,
mutations,
actions,
modules
})
const state = {
username: '',
user_state: 0 //0登陆,1已登陆
}
const mutation = {
chang_username(state, name) {
state.username = name;
},
chang_userstate(state, userstate) {
state.user_state = userstate;
}
}
const action = {
//模拟出发登陆 3s后成功
async triggerLogin(ctx) {
await setTimeout(() => {
ctx.commit('chang_username', name)
ctx.commit('chang_userstate', 1)
}, 3000)
}
}
export default {
namespaced: true,
state,
mutation,
action
}
main.js
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css';
import '@/assets/reset.css'
Vue.config.productionTip = false
Vue.use(ElementUI);
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')