
React
sqwu
这个作者很懒,什么都没留下…
展开
-
【React】组件实例的三大属性——ref
1.字符串形式的ref class Demo extends React.Component { // 自定义函数要用箭头函数,才能拿到正确的this showDlg = () => { const input = this.refs.input1 alert(input.value) } showDlg2 = () => { const input = this.refs.input2 alert(input.value) } rend原创 2022-03-01 10:46:41 · 462 阅读 · 0 评论 -
【React】组件实例的三大属性——props
props和state的区别 porps:父组件向子组件传递的参数,用于组件之间的通信,值不可变 state:组件内部的状态,值可变 1.props的用法 class Person extends React.Component { render() { const { name, age, sex } = this.props return ( <ul> <li>姓名:{name}</li> <li&原创 2022-02-28 18:55:10 · 411 阅读 · 0 评论 -
【React】组件实例的三大属性——state
1.正常的state写法(有constructor) // 1.创建组件 class Weather extends React.Component { constructor(props) { super(props) // 初始化状态 this.state = { isHot: false, wind: '微风' } // 解决changeWeather中this的指向问题 this.changeWeather = this.c原创 2022-02-28 18:20:01 · 383 阅读 · 0 评论