zl程序教程

您现在的位置是:首页 >  大数据

当前栏目

react实现双向数据绑定

数据React 实现 绑定 双向
2023-09-27 14:26:50 时间
  • 学习资源推荐:https://blog.csdn.net/qq_42813491/article/details/90213353
import React, { Component } from 'react'

class App extends Component {

    constructor(props) {
        super(props);

        this.state = {
            text: "default"
        }
       
    }
   
inputChange=(e)=>{
    this.setState({
        text:e.target.value
    })
}
    
    render() {
        return (
            <div> 
               <input  type="text" value={this.state.text} onChange={this.inputChange}/>
               <p>{this.state.text}</p>
            </div>
        )
    }

}

export default App;