页面切换导致导航重新渲染出现闪烁,有什么解决的办法吗

来源:-

慕雪6366287

2021-03-02 11:26

import React, { Component } from 'react';


import "./index.css";


const tabbarArr = [

  {

    className: 'icon-gouwuche',

    text: '购物车',

    path: '/catetory'

  },

  {

    className: 'icon-HOMEMESSAGE',

    text: '首页',

    path: '/'

  },

  {

    className: 'icon-yonghu',

    text: '用户',

    path: '/user'

  },

  {

    className: 'icon-lanlvtubiaozhizuomoban-01',

    text: '分类',

    path: '/classify'

  },

]



const TabBar  = (WarppedComponent)=> class Tabbar extends Component {

  static displayName = `Tabbar(${WarppedComponent.displayName || WarppedComponent.name })`;

  tabbarChange(i){

    const  { path } = tabbarArr[i]

    this.props.history.push(path)

  }


  render () {

    const { path } = this.props.match;

    return (

      <div>

        <div className="showContent"> 

          <WarppedComponent {...this.porps}/>

        </div>

        <div className={ 'Tablebar' }>

          {

            tabbarArr.map((item,i)=> (

              <div className={"taber-item"  + (path === item.path ? ' active-tabar' : '')} key={i}>

                <div className={ 'iconfont ' + item.className} style={{"fontSize":"20px"}} onClick={()=> this.tabbarChange(i)}></div>

                <div>{item.text}</div>

              </div>

            ))

          }

        </div>

      </div>

    )

  }

}


export default TabBar



写回答 关注

0回答

还没有人回答问题,可以看看其他问题

React高级教程之高阶组件

运用高阶组件编写高质量React应用

14485 学习 · 33 问题

查看课程

相似问题