demo1

demo1_第1张图片
屏幕快照 2018-04-19 下午7.49.13.png
import React,{Component} from 'react';

export default class coo extends Component{
    constructor(props){
        super(props)
        this.state = {
            currentVal : '',
            datas:[]
        }
    }
    handelSubmit=()=>{
        //let { value : currentValue} = this.textarea dom的值不用
        let {datas,currentVal} = this.state
        this.setState({
            currentVal : '',
            datas : [
                {
                    id : Math.random(),
                    content : currentVal
                },
                ...datas
            ],
        })
    }

    deleteValue=(id)=>{
        let {datas} = this.state
        let newDatas = datas.filter((elt)=>{
            return elt.id !== id
        })
        this.setState ({
            datas : newDatas 
        })
        console.log(datas)
    }

    changeAreaVal=(ev)=>{
        //console.log(ev.target.value)
        this.setState({
            currentVal : ev.target.value
        })
    }
   
    render(){
        let {currentVal} = this.state
        return (
            
    { this.state.datas.map((elt,i)=>{ return (
  • {i+1}.{elt.content}
  • ) }) }
) } }

你可能感兴趣的:(demo1)