项目采用create-react-app脚手架,就是做了一个效果所以只有一个页面但是也用了react-router-dom路由把details作为path=’/'首页了。
一、App.js
import React from 'react';
import {BrowserRouter,Route} from 'react-router-dom'
import Details from './routes/Details'
function App() {
return (
<div className="App">
<BrowserRouter>
<Route path='/' component={Details}></Route>
</BrowserRouter>
</div>
);
}
export default App;
web前端开发学习Q-q-u-n: 767273102 ,分享学习的方法和需要注意的小细节,不停更新最新的教程和学习方法(详细的前端项目实战教学视频)
这是入口文件的代码内容
二、Details.jsx
import React,{Component} from 'react';
import './Details.css';
import Footer from './Footer';
import SeatSelector from './SeatSelector'
class Details extends Component {
state = {
selectSeat:[]
}
addSeat = (seat)=>{
this.setState(prevState=>({
selectSeat:[...prevState.selectSeat,seat]
}))
}
removeSeat = (id)=>{
this.setState({
selectSeat:this.state.selectSeat.filter(seat=>seat.id !== id)
})