import React ,{FC} from "react";
import { TabBar } from 'antd-mobile'
import WidthUseNavigate from './../WidthUseNavigate/index'
import {
AppOutline,
MessageOutline,
UnorderedListOutline,
UserOutline,
} from 'antd-mobile-icons'
const tabs = [
{
key: '/home',
title: '首页',
icon: ,
badge: '1',
},
{
key: '/home/todo',
title: '待办',
icon: ,
badge: '2',
},
{
key: '/home/message',
title: '消息',
icon: ,
badge: '3',
},
{
key: '/home/me',
title: '我的',
icon: ,
badge: '4',
},
]
class BottomInner extends React.Component{
state = {
// 默认选中的TabBar菜单项
selectedTab: this.props.useLocation
}
// 组件接收到新的props(此处,实际上是路由信息)就会触发该钩子函数
componentDidUpdate(prevProps) {
// prevProps 上一次的props,此处也就是上一次的路由信息
// this.props 当前最新的props,此处也就是最新的路由信息
// 注意:在该钩子函数中更新状态时,一定要在 条件判断 中进行,否则会造成递归更新的问题
if (prevProps.useLocation !== this.props.useLocation) {
// 此时,就说明路由发生切换了
this.setState({
selectedTab: this.props.useLocation
})
}
}
setRouteActive = (value) => {
this.props.to(value)
this.setState({
selectedTab: value
})
}
render() {
return this.setRouteActive(value)}>
{tabs.map(item => (
))}
}
}
export function Todo() {
return
待办
}
export function Message() {
return 消息
}
export function PersonalCenter() {
return 我的
}
// 使用高阶组件包裹当前类组件
const Bottom = WidthUseNavigate(BottomInner);
export default Bottom