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

import Taro, {View,Image} from '@tarojs/components'
import PropTypes from 'prop-types'
import LsxComponent from '../component'
import './index.less'

export default class TabBar extends LsxComponent {
  constructor (props) {
    super(props);
    this.state = {
      navList: [
        {
          name: "首页",
          url: "index",
          icon: "https://cdn-test.51nwds.com/mall/0_0_0_0_7ce5f3a34c64d8db6b973c1f1acb13a7.png",
          iconCur: "https://cdn-test.51nwds.com/mall/0_0_0_0_b5751010c24636148ecfd93ab783d444.png"
        },
        {
          name: "我的",
          url: "member",
          icon: "https://cdn-test.51nwds.com/mall/0_0_0_0_41acee9b859731a6a9f9a9d2da3c6c41.png",
          iconCur: "https://cdn-test.51nwds.com/mall/0_0_0_0_f0314c9f6755b92700b3859a948d5a4d.png"
        }
      ]
    }
  }

  goRedirectTo(url){
    if(url !== this.props.curNav){
      Taro.redirectTo({
        url: '/pages/' + url + '/' + url
      });
    }
  }

  render () {

    const {
      curNav
    } = this.props;

    const {
      navList
    } = this.state;

    return <View className='lsx-tabBar'>
      {
        navList.map((item, i) =>
          <View key={i} className={`lsx-tabBar__item ${curNav === item.url ? 'active' : ''}`} onClick={this.goRedirectTo.bind(this, item.url)}>
            <View className='lsx-tabBar__item-icon'>
              <Image className='lsx-tabBar__item-icon-img' src={curNav === item.url ? item.iconCur : item.icon}/>
            </View>
            <View className='lsx-tabBar__item-text'>{item.name}</View>
          </View>
        )
      }
    </View>
  }
}

TabBar.defaultProps = {
  curNav: ''
};

TabBar.propTypes = {
  curNav: PropTypes.string
};
@import '../themes/index.less';

.lsx-tabBar {
  position: fixed;
  bottom: 0;
  z-index: 999;
  width: 100%;
  height: calc(108px + env(safe-area-inset-bottom)/2);
  float: left;
  display: flex;
  justify-content : space-around;
  border-top: 1px solid #efefef;
  background-color: #fff;
  .lsx-tabBar__item {
    display: block;
    position: relative;
    padding-top: 10px;
    &.active{
      color: #FF2424;
      .lsx-tabBar__item-text{
        color: #FF2424;
      }
    }
    .lsx-tabBar__item-icon {
      display: flex;
      justify-content: center;
      .lsx-tabBar__item-icon-img {
        width: 48px;
        height: 48px;
      }
    }
    .lsx-tabBar__item-text {
      text-align: center;
      font-size: 24px;
      color: #cccccc;
    }
  }
}

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值