store.js 722 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. Vue.use(Vuex)
  4. const state = {
  5. logined: false,
  6. loginedUser: {
  7. username: '',
  8. agency: false
  9. }
  10. }
  11. const mutations = {
  12. LOGIN (state) {
  13. state.logined = true
  14. let user = JSON.parse(localStorage.getItem('userInfo'))
  15. state.loginedUser.username = user.username
  16. // state.loginedUser.agency = user.agency
  17. },
  18. LOGOUT(state){
  19. state.logined = false
  20. state.loginedUser.username = ''
  21. // state.loginedUser.agency = false
  22. }
  23. }
  24. const actions = {
  25. login(context){
  26. context.commit('LOGIN')
  27. },
  28. logout(context){
  29. context.commit('LOGOUT')
  30. }
  31. }
  32. const getters = {
  33. }
  34. export default new Vuex.Store({
  35. state,
  36. mutations,
  37. actions,
  38. getters
  39. })