当前位置:   article > 正文

【Taro】微信小程序自定义底部菜单

taro小程序手写底部导航
  1. import Taro, {View,Image} from '@tarojs/components'
  2. import PropTypes from 'prop-types'
  3. import LsxComponent from '../component'
  4. import './index.less'
  5. export default class TabBar extends LsxComponent {
  6. constructor (props) {
  7. super(props);
  8. this.state = {
  9. navList: [
  10. {
  11. name: "首页",
  12. url: "index",
  13. icon: "https://cdn-test.51nwds.com/mall/0_0_0_0_7ce5f3a34c64d8db6b973c1f1acb13a7.png",
  14. iconCur: "https://cdn-test.51nwds.com/mall/0_0_0_0_b5751010c24636148ecfd93ab783d444.png"
  15. },
  16. {
  17. name: "我的",
  18. url: "member",
  19. icon: "https://cdn-test.51nwds.com/mall/0_0_0_0_41acee9b859731a6a9f9a9d2da3c6c41.png",
  20. iconCur: "https://cdn-test.51nwds.com/mall/0_0_0_0_f0314c9f6755b92700b3859a948d5a4d.png"
  21. }
  22. ]
  23. }
  24. }
  25. goRedirectTo(url){
  26. if(url !== this.props.curNav){
  27. Taro.redirectTo({
  28. url: '/pages/' + url + '/' + url
  29. });
  30. }
  31. }
  32. render () {
  33. const {
  34. curNav
  35. } = this.props;
  36. const {
  37. navList
  38. } = this.state;
  39. return <View className='lsx-tabBar'>
  40. {
  41. navList.map((item, i) =>
  42. <View key={i} className={`lsx-tabBar__item ${curNav === item.url ? 'active' : ''}`} onClick={this.goRedirectTo.bind(this, item.url)}>
  43. <View className='lsx-tabBar__item-icon'>
  44. <Image className='lsx-tabBar__item-icon-img' src={curNav === item.url ? item.iconCur : item.icon}/>
  45. </View>
  46. <View className='lsx-tabBar__item-text'>{item.name}</View>
  47. </View>
  48. )
  49. }
  50. </View>
  51. }
  52. }
  53. TabBar.defaultProps = {
  54. curNav: ''
  55. };
  56. TabBar.propTypes = {
  57. curNav: PropTypes.string
  58. };
  1. @import '../themes/index.less';
  2. .lsx-tabBar {
  3. position: fixed;
  4. bottom: 0;
  5. z-index: 999;
  6. width: 100%;
  7. height: calc(108px + env(safe-area-inset-bottom)/2);
  8. float: left;
  9. display: flex;
  10. justify-content : space-around;
  11. border-top: 1px solid #efefef;
  12. background-color: #fff;
  13. .lsx-tabBar__item {
  14. display: block;
  15. position: relative;
  16. padding-top: 10px;
  17. &.active{
  18. color: #FF2424;
  19. .lsx-tabBar__item-text{
  20. color: #FF2424;
  21. }
  22. }
  23. .lsx-tabBar__item-icon {
  24. display: flex;
  25. justify-content: center;
  26. .lsx-tabBar__item-icon-img {
  27. width: 48px;
  28. height: 48px;
  29. }
  30. }
  31. .lsx-tabBar__item-text {
  32. text-align: center;
  33. font-size: 24px;
  34. color: #cccccc;
  35. }
  36. }
  37. }

 

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
  

闽ICP备14008679号