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

Vue.use(Vuex); //vue的插件机制

//Vuex.Store 构造器选项
const store = new Vuex.Store({
	state: { //存放状态
		username: "admin",
		token: 'c74d427b805beeb5501345f87f1a55af',
	},
	getters: {
		metadata: state => {
			return {
				token: state.token
			}
		}
	},
	mutations: {
		setUsername(state, username) {
            state.username = username;
            console.log("[setUsername] state.username = " + username);
        },
		setToken(state, token) {
		    state.token = token;
		    console.log("[setUsername] state.token = " + token);
		},
	}
})

export default store