
React
今天也很棒棒~
今天也很棒棒
展开
-
React 路由第一步
原创 2021-11-12 17:44:24 · 492 阅读 · 0 评论 -
React生命周期函数
React生命周期函数: 组件加载之前,组件加载完成,以及组件更新数据,组件销毁。 触发的一系列的方法 ,这就是组件的生命周期函数组件加载的时候触发的函数: constructor 、componentWillMount、 render 、componentDidMount组件数据更新的时候触发的生命周期函数: shouldComponentUpdate、componentWillUpdate、render、componentDidUpdate你在父...原创 2021-11-11 17:52:28 · 513 阅读 · 0 评论 -
React:Axios、Fetch-Jsonp获取API接口数据
不同模块可登录npm,搜索对应方法有官方文档https://www.npmjs.com/Axios步骤:{/* axios 1. npm install axios --save 安装axios模块 2. import axios from 'axios' ; 3. var api='http://www.phonegap100.com/appapi.php?a=getPortalList&catid=20'; //接口后台允许了原创 2021-11-11 14:58:36 · 579 阅读 · 0 评论 -
React父子组件传值默认值,传值类型
1.传值默认值defaultProps父组件调用子组件不传值,则可以在子组件中defaultProps设置默认值父组件调用时未传值return ( <div> <Son num='123'></Son> </div> );.原创 2021-11-11 09:51:04 · 1838 阅读 · 0 评论 -
React父子组件调用
1.父组件传值给子组件render() { return ( <div> <h1>父组件</h1> <TestSon t={this.state.father}/> </div> ); }父组件传值:< 子组件 {this.state.变量.原创 2021-11-10 18:11:16 · 327 阅读 · 0 评论 -
React 临时缓存数据
1.react 临时缓存数据checkboxChange=(key)=>{ let temp=this.state.list ; temp[key].checked=! temp[key].checked this.setState({ list : temp }) localStorage.setItem('todoList',JSON.stringify(temp)) //只能保存数据原创 2021-11-09 11:28:22 · 2230 阅读 · 0 评论 -
React 例子1
1.输入框中:回车自动增加到待办事项2.待办事项中:勾选方框自动增加到已办事项3.已完成事项:取消勾选自动增加到待办事项待办事项:checked:false;已完成事项 :checked:true1.回车增加待办事项addData=(e)=>{ if(e.keyCode==13){ var temp=this.state.list ; temp.push({ title:this.refs.ti.原创 2021-11-08 18:01:29 · 238 阅读 · 0 评论 -
React 使用ref绑定 增加删除数组
1.增加 <input ref="title" ></input> <button onClick={this.addData}>增加+</button>addData=()=>{ var temp=this.state.list ; temp.push(this.refs.title.value); this.refs.title.value='' ;原创 2021-11-08 16:30:31 · 822 阅读 · 0 评论 -
React表单
1.react提交文本框 render() { return ( <div> <form onSubmit={this.handleSubmit}> 用户名:<input type='txt' value={this.state.name} onChange={this.handleName}> ..原创 2021-11-08 14:30:08 · 1035 阅读 · 0 评论 -
React改变this指向的三种方法
组件名称Home.js基本代码;importReactfrom"react";classHome1extendsReact.Component{constructor(props){ super(props); this.state={ msg:'zhesh' } } render(){ ...原创 2021-11-06 10:15:23 · 711 阅读 · 0 评论 -
React组件
一、组件基本结构import React ,{Component} from "react";class Test extends Component { constructor(props){ super(props); this.state={ } } render() { return ( <div> <h2>所有内容都需要原创 2021-11-06 17:24:37 · 83 阅读 · 0 评论 -
React 安装
一、安装1.安装nodejs :下载 | Node.js 中文网建议安装nodejs稳定版本(最新版本安装要求window8.0以上版本)2.安装cnpm:http://npm.taobao.org/npm install -g cnpm --registry=https://registry.npm.taobao.org3.用yarn替代npm yarn的安装: 第一种方法:参考官方文档https://yarn.bootcss....原创 2021-11-06 17:05:50 · 633 阅读 · 0 评论 -
React绑定
每一个对象展示都需要一个key,否则会弹出警告一、绑定对象1. 循环方法1:在return()方法中循环 <ul> { this.state.list2.map(function(value,key){ return (<li key={key}>{value.title}</li>);原创 2021-11-06 17:54:13 · 179 阅读 · 0 评论 -
React双向数据绑定
MVVM1.MV:mode改变viewsetName=()=>{ this.setState({ name:'张三' }) }<button onClick={this.setName} >改变name的值</button>2.VM:view改变model在网站文本框中输入值可以改变变量取值constructor(props){ super(props);原创 2021-11-08 15:01:55 · 201 阅读 · 0 评论