react的代码-Input学习

Input

看代码:

import React, { Component } from "react"
import { Input, Modal, Button } from 'antd';


class Toast extends React.Component{
    constructor(){
        super()
        this.state={
            jobNumber2:''
        }
    }
    jobNumber2
    componentDidMount=()=>{
        console.log('componentDidMount-start')
        console.log(this.props.jobNumber)
        this.jobNumber2 = this.props.jobNumber
        console.log('componentDidMount-end')
    }
    
    handleNumber2=(e)=>{
        console.log(e.target.value)
        this.setState({
            jobNumber2:e.target.value
        })
    };
    handleClick1 = ()=>{
        console.log(this.refs.inputtest)
    }

    render(){
        this.jobNumber2 = this.props.jobNumber
        return (
            <div>
                <Input placeholder="请输入"
                    style={{width:"150px"}}
                    onChange={this.handleNumber2}
                    defaultValue={this.jobNumber2}
                    key={this.jobNumber2} ref="inputtest"></Input>
                <Button onClick={this.handleClick1}>确认</Button>
            </div>
        )
    }
    
}

export default Toast
import React from 'react'
import ReactDom from 'react-dom'
import { useState } from 'react';
import Toast from './toast'
import { TreeSelect,Input,Button, Modal } from 'antd';


class Test extends React.Component{
  constructor(){
    super()
    this.state={
      jobNumber: "",
      visible:false
    }
  };
  handleNumber = (e) =>{
    console.log(e.target.value)
    this.setState({
      jobNumber:e.target.value
    })
  };
  handleChangeValue =(e)=>{
    this.setState({
      visible:true
    })
  };
  handleOk=e=>{
    console.log(e)
    console.log(this.refs.toast)

    this.setState({
      visible:false,
      jobNumber:this.refs.toast.state.jobNumber2
    })
  };
  handleCancle=e=>{
    console.log(e)
    this.setState({
      visible:false
    })
  };

  render(){
    return (
      <div>
        <Input placeholder='请输入' style={{width:"150px"}} onChange={this.handleNumber} value={this.state.jobNumber}></Input>
        <Button type='primary' onClick={this.handleChangeValue}> 传值 </Button>
        <Modal 
          title='Basic Modal'
          open={this.state.visible}
          onOk={this.handleOk}
          onCancel={this.handleCancle}
          >
            <Toast jobNumber={this.state.jobNumber} ref="toast"></Toast>
        </Modal>
      </div>
    )
  }
}

const element = <Test></Test>

ReactDom.render(element,document.getElementById('root'))

看效果
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值