zoukankan      html  css  js  c++  java
  • todolist拆分为逻辑页面和ui页面

    我们可以把Todolist 继续拆分 ,拆分为逻辑页面和ui页面

    ui 页面

    import React, { Component } from 'react';import 'antd/dist/antd.css'; // or 'antd/dist/antd.less'import { DatePicker } from 'antd';import { Input ,Button,List} from 'antd';class TodoListUi extends Component { render() { return ( <React.Fragment> <h3 style={{ marginBottom: 16 }}>TodoList</h3> <Input value={this.props.inputValue} placeholder="todolist输入框" style={{"300px","marginRight":"10px"}} onChange={this.props.handleChangeInput} /> <Button type="primary" onClick={this.props.handleChangeButton}>提交</Button> <List style={{"300px"}} bordered dataSource={this.props.list} renderItem={(item,index) => (<List.Item onClick={(index)=>{this.props.deleteItem(index)}}>{item}</List.Item>)} /> </React.Fragment> ) }}export default TodoListUi;

    记得 我们这里的数据和方法要从 父组件传过来,也就是原来的 逻辑页面传递过来 ,

    传递过来 的数据 ,要这么写 this.props.数据

    传递过来的方法 ,要这么写 this.props.方法

    如果方法有参数,就使用es6 语法

    renderItem={(item,index) => (<List.Item onClick={(index)=>{this.props.deleteItem(index)}}>{item}</List.Item>)}

    逻辑页面

    import React, { Component } from 'react';import 'antd/dist/antd.css'; // or 'antd/dist/antd.less'import { DatePicker } from 'antd';import { Input ,Button,List} from 'antd';import store from './store/index'import {getInputChangeAction, getAddItemAction ,getDeleteItemAction} from './store/actionCreators'import {CHANGE_INPUT_VALUE,ADD_ITEM,DELETE_ITEM} from './store/actionType'import TodoListUi from './store/TodoListUi'class App extends Component { constructor(props) { super(props); this.state=store.getState(); this.handleChangeInput = this.handleChangeInput.bind(this); this.handleChange = this.handleChange.bind(this); this.handleChangeButton= this.handleChangeButton.bind(this); this.deleteItem = this.deleteItem.bind(this); store.subscribe(this.handleChange); } render() { return ( <TodoListUi inputValue = {this.state.inputValue} list = {this.state.list} handleChangeInput = {this.handleChangeInput} handleChangeButton = {this.handleChangeButton} deleteItem = {this.deleteItem} /> ); } handleChangeInput(e) { const action = getInputChangeAction(e.target.value); store.dispatch(action); }; handleChange(e) { this.setState(store.getState()) } handleChangeButton() { const action = getAddItemAction(); store.dispatch(action); } deleteItem(index) { const action = getDeleteItemAction(index); store.dispatch(action); }}

    export default App;

    1.首先我们要引入我们写的ui页面2。将数据和方法重写,传递给ui页面

    <TodoListUi inputValue = {this.state.inputValue} list = {this.state.list} handleChangeInput = {this.handleChangeInput} handleChangeButton = {this.handleChangeButton} deleteItem = {this.deleteItem} />

     

  • 相关阅读:
    WIN32窗口框架代码,完善了菜单和子窗口,纯API,可自由扩展,C语言也可以写桌面程序
    自制WINDOWS窗口框架(修改完善后实现了输入和显示功能),C+WIN-API,再也不用面对黑框框学C语言了
    定义一个判断素数的函数
    定义一元二次方程求根函数
    定义一个二维数组反置函数
    让C语言告别简陋的黑框框,WIN32窗口显示九九乘法表(纯C代码)
    C语言练习题40——将一个数组逆序输出
    c语言练习39——向数列中插入一个数
    c语言练习38——求3*3矩阵对角线之和
    js之好看的鼠标点击-光标特效
  • 原文地址:https://www.cnblogs.com/guangzhou11/p/9808844.html
Copyright © 2011-2022 走看看