react简单实现模块跳转

import React,{Component} from 'react';
class View extends Component {
  constructor(props) {
    super(props);
    this.state = {
      cls: 'parent_one',
            name: '',
            age: '',
            cla:''
    }
  }
  changeCls(cls) {
        this.setState({
            cls: cls
        })
  }
   One() {
        this.changeCls('parent_two')
  }
   Two() {
            this.changeCls('parent_thre')

  }
   Thre() {
        this.changeCls('parent_four')
  }
   four() {
        this.changeCls('parent_five')
    }
      five() {
        this.changeCls('parent_one')
    }
     setValue(e) {
        let value = e.target.value;
        let name = e.target.name;
        this.setState({
            [name]: value ,
        })
    }
  render() {
        const { cls, name, age,cla } = this.state
    return (
      <React.Fragment>
        <div className={`show_hide ${cls}`}>
          {/* 块一 */}
          <div className='one'>
            <h1>准备开始驾考考试</h1>
              <p className='p' onClick={() => { this.One() }}>开始考试</p>
          </div>
          {/* 块二 */}
            <div className='two'>
              <h1>二、开始考试</h1>
            姓名:<input type="text" name='name' value={name} onChange={(e) => { this.setValue(e) }} placeholder='用户名' />
            <br />
            年龄: <input type="text" name='age' value={age} onChange={(e) => { this.setValue(e) }} placeholder='年龄' />
            <br />
           科目:<input type="text" name='cla' value={cla} onChange={(e) => { this.setValue(e) }} placeholder='内容' />    
                  <p onClick={() => { this.Two() }} className='sp1'>准备上机</p>
          </div>
           {/* 块三 */}
           <div className='thre'>
                    <h1>三、上机了</h1>
                    <div>名字:{name}</div>
              <div>年龄:{age}</div>
              <div>内容:{cla}</div>
                        <p onClick={() => { this.Thre() }} className='sp1'>完成上机</p>
                    </div>
            {/* 块四 */}
                <div className='four'>
                    <h1>四、我已完成机试,准备道路驾驶</h1>
                    <p onClick={() => { this.four() }} className='sp'>准备面试</p>
                </div>
          {/* 块五 */}
          <div className='five'>
            <h1>五、等待驾驶</h1>
              <p className="sp" onClick={()=>{this.five()}}>返回首页</p>
          </div>
        </div>
      </React.Fragment>
    );
  }
}

export default View;

.show_hide {
	width: 900px;
	margin: 0 auto;
	text-align: center;
	.one {
		width: 900px;
		height: 400px;
		display: none;
		border: 1px solid black;
		h1 {
			font-size: 28px;
		}
		.p {
			width: 200px;
			height: 60px;
			background: rgb(36, 179, 204);
			color: white;
			margin: 0 auto;
			margin-top: 200px;
			font-size: 34px;
		}
	}
	.two {
		width: 900px;
		display: none;
		height: 400px;
		border: 1px solid black;
		h1 {
			font-size: 28px;
		}
		input {
			margin: 10px 0;
		}
		span {
			display: inline-block;
		}
		.sp1 {
			width: 240px;
			height: 60px;
			background: rgb(36, 179, 204);
			color: white;
			margin: 0 auto;
			margin-top: 100px;
			font-size: 34px;
		}
		.sp2 {
			width: 30px;
			height: 20px;
			background: skyblue;
			color: white;
		}
	}
	.thre {
		width: 900px;
		height: 400px;
		border: 1px solid black;
		display: none;
		h1 {
			font-size: 28px;
		}
		.sp1 {
			width: 240px;
			height: 60px;
			background: rgb(36, 179, 204);
			color: white;
			margin: 0 auto;
			margin-top: 100px;
			font-size: 34px;
		}
		.sp2 {
			width: 30px;
			height: 20px;
			background: skyblue;
			color: white;
		}
	}
	.four {
		width: 900px;
		height: 400px;
		border: 1px solid black;
		display: none;
		h1 {
			font-size: 28px;
		}
		.sp {
			width: 240px;
			height: 60px;
			background: rgb(36, 179, 204);
			color: white;
			margin: 0 auto;
			margin-top: 100px;
			font-size: 34px;
		}
	}
	.five {
		width: 900px;
		height: 400px;
		border: 1px solid black;
		display: none;
		h1 {
			font-size: 28px;
		}
		.sp {
			width: 240px;
			height: 60px;
			background: rgb(36, 179, 204);
			color: white;
			margin: 0 auto;
			margin-top: 100px;
			font-size: 34px;
		}
	}
	&.parent_one {
		.one {
			display: block;
		}
	}
	&.parent_two {
		.two {
			display: block;
		}
	}
	&.parent_thre {
		.thre {
			display: block;
		}
	}
	&.parent_four {
		.four {
			display: block;
		}
	}
	&.parent_five {
		.five {
			display: block;
		}
	}
}

scss语法编写

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值