美文网首页
React开发之入门

React开发之入门

作者: Hamiltonian | 来源:发表于2022-12-15 09:42 被阅读0次

React开发之入门

A. 创建对象时:new,

B.this 指向属性、指向函数方法

C.Constructor 方法可选,里面bind绑定函数this

    constructor(props) {
        super(props);
        this.state = {date: new Date(),count:0,store:this.props.store};
        this.addPrice = this.addPrice.bind(this);
        this.addAmount = this.addAmount.bind(this);
      }

D.State 负责管理函数内部状态【可读写】,props 负责接收从父控件传入的参数【只读】

this.props.myDataProp
<Content myDataProp = {value} 
              updateStateProp = {this.handleChange}></Content>

this.state = {value: 'Hello Runoob!'};
this.setState({value: event.target.value});

E.用构造函数创建出来的组件:无状态组件【只有props,没有state、没有生命周期函数、性能高】类似StatefulWidget

F.用class关键字创建出来的组件:有状态组件【props、state都有、有生命周期函数、性能略低】StatelessWidget

G.import析构【import { } from “”】、export【export default】

相关文章

网友评论

      本文标题:React开发之入门

      本文链接:https://www.haomeiwen.com/subject/pzcrqdtx.html