注: 每个底部导航页面里都要有该代码才能生效
1. pages.json 生效代码 “custom”: true
"tabBar": {
"custom": true,
"list": [
{
"pagePath": "pages/index/index"
},
{
"pagePath": "pages/my/index"
}
]
}
2.使用代码管理动态渲染绑定值
state: {
pageValue: 0,
pageList: [
{
path: 'pages/index/index',
text: '首页',
icon: 'home'
},
{
path: 'pages/my/index',
text: '我的',
icon: 'account'
},
]
},
getters: {
pageList: state => state.pageList,
pageValue: state => state.pageValue
},
mutations: {
SET_PAGE(state, data) {
state.pageValue = data
}
},
actions: {}
3. 页面具体使用及完善
<u-tabbar
:value="pageValue"
:fixed="true"
:border="false"
:placeholder="true"
:safeAreaInsetBottom="true"
>
<u-tabbar-item
v-for="item in pageList"
:key="item.path"
:icon="item.icon"
:text="item.text"
@click="clickPage(item)"
/>
</u-tabbar>
import { mapGetters, mapMutations } from 'vuex'
computed: {
...mapGetters(['pageValue']),
...mapGetters(['pageList'])
},
methods: {
...mapMutations(['SET_PAGE']),
clickPage(item) {
this.SET_PAGE(index)
uni.navigateTo({
url: item.path
})
}
}