金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.6 KiB

  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. Vue.use(Vuex)
  4. let state = {
  5. currentTabBar: 0,
  6. tabbars: [
  7. {
  8. name: 'home',
  9. text: '首页',
  10. icon: 'icon-xianxingicon-03',
  11. path: '/pages/index/index/index'
  12. },
  13. {
  14. name: 'brand',
  15. text: '品牌',
  16. icon: 'icon-pinpailiebiao',
  17. path: '/pages/index/category/category'
  18. },
  19. {
  20. name: 'find',
  21. text: '发现',
  22. icon: 'icon-faxian',
  23. path: '/pages/discover/discover'
  24. },
  25. {
  26. name: 'my',
  27. text: '会员中心',
  28. icon: 'icon-icon',
  29. path: '/pages/user/my/center'
  30. }
  31. ],
  32. isShowTabBar: true
  33. }
  34. let mutations = {
  35. // 修改tabbar当前选中的item
  36. setCurrentTabBar(state, data){
  37. state.currentTabBar = data;
  38. },
  39. // 显示tabbar
  40. showTabBar(state, data){
  41. state.isShowTabBar = true;
  42. },
  43. // 隐藏tabbar
  44. hideTabBar(state, data){
  45. state.isShowTabBar = false;
  46. }
  47. }
  48. let actions = {
  49. // 异步调用修改tabbar当前选中的item
  50. setCurrentTabBarAsync(context, args){
  51. context.commit('setCurrentTabBar', args);
  52. }
  53. }
  54. let getters = {
  55. currentTabBar: state => state.currentTabBar,
  56. tabbars: state => state.tabbars,
  57. isShowTabBar: state => state.isShowTabBar
  58. }
  59. export default new Vuex.Store({
  60. state,
  61. mutations,
  62. actions,
  63. getters
  64. })
  65. /*
  66. getters可以认为是 store 的计算属性然后在组件的计算属性中使用...mapGetters([])
  67. mutations: 修改state的值调用store.commit('test', 'hello')
  68. actions: 异步提交mutations
  69. module区分模块每个模块都有自己的 statemutationactiongetter甚至是嵌套子模块(项目大时可能需要用到)
  70. */