import * as React from 'react'; interface PropsItem { idx: string, //string,标签的唯一标识名称 title: string, //string,标签内容 active: boolean, //boolean } interface Props { item: PropsItem tabClick: (idx: any, item: PropsItem) => any index: number addWidth: Function } export default class Item extends React.PureComponent{ ele: any; handleClick = (e: React.MouseEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); this.props.tabClick(this.props.item.idx, this.props.item) } componentDidMount() { this.addWidth() } componentDidUpdate(prevProps: Props) { this.addWidth() } componentWillUnmount() { console.log('componentWillUnmount', this.props.item.title) } addWidth = () => { const { item, index, addWidth } = this.props; addWidth && addWidth(item.active, index, this.ele.clientWidth); } render() { const { title, active } = this.props.item, titleClass = active ? 'item-title item-choosed' : 'item-title'; return
this.ele = node} onClick={this.props.tabClick(this.props.item.idx, this.props.item)}>
{title}
} }