<template>
<view class="bottom-menu">
<u-tabbar
:value="tabIndex"
:list="list"
:mid-button="true"
@change="onChangBar"
active-color="#FF5394"
inactiveColor="#666666"
>
<u-tabbar-item
v-for="(tabbar, index) in list"
:text="tabbar.text"
:icon="tabbar.iconPath"
:key="index"
></u-tabbar-item>
</u-tabbar>
</view>
</template>
<script>
import {mapState} from "vuex";
export default {
data() {
return {
list: [
{
pagePath: "pages/index/index",
iconPath: "home",
selectedIconPath: "home-fill",
midButton: true,
text: "创作",
customIcon: false,
},
{
pagePath: "pages/picList/picList",
iconPath: "photo",
selectedIconPath: "photo-fill",
text: "艺廊",
customIcon: false,
},
{
pagePath: "pages/works/works",
iconPath: "play-right",
selectedIconPath: "play-right-fill",
text: "画板",
customIcon: false,
},
{
pagePath: "pages/mine/mine",
iconPath: "account",
selectedIconPath: "account-fill",
text: "我的",
isDot: false,
customIcon: false,
},
],
};
},
computed: mapState({
tabIndex: "tabIndex",
}),
methods: {
async onChangBar(index) {
if (this.tabIndex !== index) {
await uni.$u.route({
type: "switchTab",
url: this.list[index].pagePath,
});
this.$store.state.tabIndex = index;
}
},
},
};
</script>
<style lang="scss"></style>
"tabBar": {
"color": "#7A7E83",
"selectedColor": "#3cc51f",
"borderStyle": "white",
"backgroundColor": "#f4f5f7",
"custom": true,
"list": [
{
"pagePath": "pages/index/index"
},
{
"pagePath": "pages/picList/picList"
},
{
"pagePath": "pages/works/works"
},
{
"pagePath": "pages/mine/mine"
}
]
},
import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex);
const store = new Vuex.Store({
state: {
tabIndex: 0,
},
});
export default store;
Vue.component("tab-bar", tabBar);
Vue.prototype.$store = store;
const app = new Vue({
store,
...App,
});