深入浅出react
发布时间:2020-12-15 20:29:39 所属栏目:百科 来源:网络整理
导读:1,新建项目 为了方便安装一个初始化简单的 react组件,我们可以先通过 npm 来安装 create-react-app ? ? npm install --global create-react-app ? create-react-app first_react_app ? 注意: create-react-app默认的是 npm镜像 ? 由于 npm属于国外镜像,
1,新建项目 为了方便安装一个初始化简单的react组件,我们可以先通过npm 来安装create-react-app? ? npm install --global create-react-app? create-react-app first_react_app? 注意:create-react-app默认的是npm镜像? 由于npm属于国外镜像,有时候安装会很慢。解决办法 通过换源:npm config set registry https://registry.npm.taobao.org? 默认设成淘宝镜像 检验是否换源成功:npm info express或者npm config get registry ? 启动项目 npm start ? 1.2增加一个新的 React组件? import React,{ Component } from ‘react‘; class ClickCounter extends Component { constructor(props) { super(props) this.onClickButton = this.onClickButton.bind(this); this.state = { count: 0 } } onClickButton() { this.setState({ count: this.state.count + 1 }) } render() { const { count } = this.state return ( <div> <div> <button onClick={this.onClickButton}>大师马快点我</button> </div> <p> 你点了{count}次 </p> </div> ) } } export default ClickCounter (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |