React简单实现双向数据绑定
程序员文章站
2022-09-09 15:09:58
import React, { Component } from 'react' import ReactDOM from 'react-dom' class App extends Component { constructor(props) { super(props); this.state ... ......
import react, { component } from 'react' import reactdom from 'react-dom' class app extends component { constructor(props) { super(props); this.state = { val:"react的双向数据绑定" } } change=(event)=>{ this.setstate({val:event.target.value}) } render() { return ( <div> <input type="text" value={this.state.val} onchange={this.change} /> {this.state.val} </div> ); } } reactdom.render(<app/>,window.root) /* event 事件对象 event.target 事件源 利用了event.target这个事件源去更新react中的数据状态 */
上一篇: 奇趣毛毛虫造型的USB HUB
下一篇: c语言指针篇