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
76 lines
1.6 KiB
import Vue from 'vue'
|
|
import Vuex from 'vuex'
|
|
Vue.use(Vuex)
|
|
|
|
let state = {
|
|
currentTabBar: 'home',
|
|
tabbars: [
|
|
{
|
|
name: 'home',
|
|
text: '首页',
|
|
icon: 'dingzhi',
|
|
path: '/pages/index/index/index'
|
|
},
|
|
{
|
|
name: 'brand',
|
|
text: '品牌',
|
|
icon: 'weirenzheng',
|
|
path: '/pages/index/classification/classification'
|
|
},
|
|
{
|
|
name: 'find',
|
|
text: '发现',
|
|
icon: 'nv',
|
|
path: '/pages/store/cart/cart'
|
|
},
|
|
{
|
|
name: 'my',
|
|
text: '我的',
|
|
icon: 'contact-person',
|
|
path: '/pages/user/personal/personal'
|
|
}
|
|
],
|
|
isShowTabBar: true
|
|
}
|
|
|
|
let mutations = {
|
|
// 修改tabbar当前选中的item
|
|
setCurrentTabBar(state, data){
|
|
state.currentTabBar = data;
|
|
},
|
|
// 显示tabbar
|
|
showTabBar(state, data){
|
|
state.isShowTabBar = true;
|
|
},
|
|
// 隐藏tabbar
|
|
hideTabBar(state, data){
|
|
state.isShowTabBar = false;
|
|
}
|
|
}
|
|
|
|
let actions = {
|
|
// 异步调用修改tabbar当前选中的item
|
|
setCurrentTabBarAsync(context, args){
|
|
context.commit('setCurrentTabBar', args);
|
|
}
|
|
}
|
|
|
|
let getters = {
|
|
currentTabBar: state => state.currentTabBar,
|
|
tabbars: state => state.tabbars,
|
|
isShowTabBar: state => state.isShowTabBar
|
|
}
|
|
|
|
export default new Vuex.Store({
|
|
state,
|
|
mutations,
|
|
actions,
|
|
getters
|
|
})
|
|
|
|
/*
|
|
getters:可以认为是 store 的计算属性,然后在组件的计算属性中使用:...mapGetters([])
|
|
mutations: 修改state的值,调用:store.commit('test', 'hello')
|
|
actions: 异步提交mutations
|
|
module:区分模块,每个模块都有自己的 state、mutation、action、getter、甚至是嵌套子模块(项目大时可能需要用到)
|
|
*/
|