金诚优选前端代码
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.

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