世界上最伟大的投资就是投资自己的教育

loungcingzeon


id 759


9 minutes 33 seconds 学徒 中学生


  • React 基础实践篇免费视频教程 - 小型财务系统 #2 实现 records 列表页

    import React, { PureComponent } from 'react';

    import Record from './Record';

    class Records extends PureComponent{

     constructor(props){
         super(props);
         this.state = {
             records: [
                 {"id": 1, "date": "2018-01-09", "title": "收入", "amount": 20},
                 {"id": 2, "date": "2018-01-03", "title": "录视频收入", "amount": 199},
                 {"id": 2, "date": "2018-01-03", "title": "录视频收入", "amount": 199},
             ]
         }
     }
    
     render(){
         return (
             <div className="records">
                 <h2>Records</h2>
                 <table className="table table-borderd">
                     <thead>
                         <tr>
                             <th>Date</th>
                             <th>Title</th>
                             <th>Amount</th>
                         </tr>
                     </thead>
                     <tbody>
                        <Record recordData={this.state.records}/>
                     </tbody>
                 </table>
             </div>
         );
     }
    

    }

    export default Records;

    import React, { PureComponent } from 'react';
    import PropTypes from 'prop-types';

    class Record extends PureComponent{
    static propTypes = {
    recordData: PropTypes.array.isRequired,
    }

    render(){
        const { recordData=[] } = this.props;
        console.log(recordData);
        return (
            recordData && recordData.map((item, index) => {
                return <tr key={index}>
                            <td>{item.date}</td>
                            <td>{item.title}</td>
                            <td>{item.amount}</td>
                        </tr>
            })
        );
    }
    

    }

    export default Record;

  • 诱人的 React 免费视频教程 - 基础篇 #13 双向数据绑定

    value={this.state.initialName} 大佬,应该是不是应该如下,这样设置好一点呢。我看你 初始值也没有,

    this.state = {

    initialName:'',
    }

    onHandleChange = (event) => {
    this.setState({
    homeLink: event.target.value,
    initialName: event.target.value,
    })

        console.log(event.target.value);
    }
    

    {this.state.initialName}

    this.onHandleChange(event)} /> Change Header Link

© 汕尾市求知科技有限公司 | Rails365 Gitlab | 知乎 | b 站 | csdn

粤公网安备 44152102000088号粤公网安备 44152102000088号 | 粤ICP备19038915号

Top