1.通過父元件傳遞類名給子元件的方法 (第十九行)
2.通過不同的狀态值,應用某些類名 (第22行)
[javascript] view plain copy
- import React from 'react'
- import './style.css'
- class PageTitle extends React.Component {
- constructor(props, context) {
- super(props, context);
- this.state = {
- timeType:0
- }
- }
- handleClick(timeType){
- this.setState({
- timeType:timeType
- });
- this.props.handle(timeType+1);
- }
- render() {
- const {title,dataList} = this.props;
- return (
- <h3 className={this.props.clasName+" cp_title"}>{title}
- <div className="floatR">
- {dataList.map((item,index) => {
- return <span key={index} onClick={this.handleClick.bind(this,index)} className={this.state.timeType === index ? "canvasNav canvasNavActive": "canvasNav"}>{item}</span>
- })}
- </div>
- </h3>
- )
- }
- }
- export default PageTitle;