博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
material-ui的BottomNavigation的使用
阅读量:2120 次
发布时间:2019-04-30

本文共 2335 字,大约阅读时间需要 7 分钟。

准备:下载 npm i @material-ui/core @material-ui/icons

这里在单独将BottomNavation再次封装组件使用(使用了react父子通信的知识):

因为底部导航通常是作为公共出现的布局,所以这里放在app.jsx中

import React, { Component } from 'react';import {Link,Route,Switch,Redirect} from "react-router-dom";import Home from './views/home/Home.jsx'import Account from './views/account/Account.jsx'import Goods from './views/goods/Goods.jsx'import './App.scss';import FooterNav from './components/smallComponents/footerNav.jsx'class App extends Component {  changeRoute=(routerName)=>{      this.props.history.push(routerName);  }  render() {    return (        
); }}export default App;

接着,在FooterNav.jsx中

import React from 'react';import PropTypes from 'prop-types';import BottomNavigation from '@material-ui/core/BottomNavigation';import BottomNavigationAction from '@material-ui/core/BottomNavigationAction';import HomeIcon from '@material-ui/icons/Home';import DashboardIcon from '@material-ui/icons/Dashboard';import FaceIcon from '@material-ui/icons/Face';import './style.scss'class FooterNav extends React.Component {    state = {        value: 0,    };    static propTypes = {        appThis: PropTypes.object.isRequired,    }    componentWillMount(){        //处理页面刷新时value重置的问题        var current=this.props.appThis.props.location.pathname;        if(current=='/home'){            this.setState({ value:0 });        }else if(current=='/goods'){            this.setState({ value:1 });        }else if(current=='/account'){            this.setState({ value:2 });        }    }    handleChange = (event, value) => {        this.setState({ value });        var routerName='';        if(value==0){            routerName='/home'        }else if(value==1){            routerName='/goods'        }else if(value==2){            routerName='/account'        }        this.props.appThis.props.history.push(routerName);    };    render() {        const { value } = this.state;        const { classes } = this.props;        return (            
} />
} />
} />
); }}export default FooterNav;

 

转载地址:http://xnurf.baihongyu.com/

你可能感兴趣的文章
云原生 第十三章 Kubernetes网络概念及策略控制
查看>>
《redis设计与实现》 第一部分:数据结构与对象 || 读书笔记
查看>>
《redis设计与实现》 第二部分(第9-11章):单机数据库的实现
查看>>
算法工程师 面经2019年5月
查看>>
搜索架构师 一面面经2019年6月
查看>>
稻草人手记
查看>>
第一次kaggle比赛 回顾篇
查看>>
leetcode 50. Pow(x, n)
查看>>
leetcode 130. Surrounded Regions
查看>>
【托业】【全真题库】TEST2-语法题
查看>>
博客文格式优化
查看>>
【托业】【新托业全真模拟】疑难语法题知识点总结(01~05)
查看>>
【SQL】group by 和order by 的区别。
查看>>
【Python】详解Python多线程Selenium跨浏览器测试
查看>>
Jmeter之参数化
查看>>
Shell 和Python的区别。
查看>>
Python 列表(list)、字典(dict)、字符串(string)常用基本操作小结
查看>>
Loadrunner之https协议录制回放报错如何解决?(九)
查看>>
python中xrange和range的异同
查看>>
列表、元组、集合、字典
查看>>