高中英语语法知识点高中英语语法知识点问题

React Native 语法指南 - 简书
React Native 语法指南
React Native真的是越来越流行,没使用React Native开发项目都不好意思说自己是搞客户端开发的。对于纯Native开发者来说,刚上手React Native有一定的适应期,如果JavaScript也不熟练的话那就更悲催了。React Native涉及ES6,React语法,JSX,前端调试,Native客户端等知识,本文简单总结了React Native开发中一些知识点。算是在学习中的积累。
Component:组件,使用React.createClass或者extends React.Component创建的类为组件。
Element:元素或者可以说是组件的实例,使用&Label /&或者let label = new Label()创建的为实例。
对于定义组件,React以前版本的写法(ES5):
= React.createClass({
React最新的写法(ES6):
class Label extends React.Component{
props与state
props属性:组件可以定义初始值,自己不可更改props属性值,只允许从父组件中传递过来:
class MainComponent extends React.Component{
return(&Label name="标题栏"&);
class Label extends React.Component{
return(&Text&{this.props.name}&/Text&);
父组件向Label传递name="标题栏"的props属性,在Label中使用this.props.name引用此属性。
state属性:组件用来改变自己状态的属性,通常使用setState({key:value})来改变属性值,不能使用this.state.xxx来直接改变,setState({key:value})方法会触发界面刷新。
对于经常改变的数据且需要刷新界面显示,可以使用state。对于不需要改变的属性值可以使用props。React Native建议由顶层的父组件定义state值,并将state值作为子组件的props属性值传递给子组件,这样可以保持单一的数据传递。
在以前版本的React中定义state,props可以使用生命周期方法 getInitialState()和getInitialState():
var Label = React.createClass({
getInitialState(){
key:value,
getInitialProps(){
key:value,
},// 这种写法需要有,不要使用;
render:funation(){
在最新版本的React可以使用构造函数替代getInitialState(),getInitialState()方法定义初始值:
class Label extends React.Component{
constructor(props) {
super(props);
this.state = {
time: '2016',
city: '上海',
this.props = {
name:'标题',
默认props与props校验
class Label extends React.Component{
constructor(props) {
super(props);
// 默认props
static defaultProps = {
city: '南京',
index: 12,
// propTypes用于验证转入的props,当向 props 传入无效数据时,JavaScript 控制台会抛出警告
static propTypes = {
city: React.PropTypes.string.isRequired,
index: React.PropTypes.number.isRequired,
city: this.props.city,
index:this.props.index,
class Label extends React.Component{
constructor(props) {
super(props);
// 默认props
Label.defaultProps = {
city: '南京',
index: 12,
// propTypes用于验证转入的props,当向 props 传入无效数据时,JavaScript 控制台会抛出警告
Label.propTypes = {
city: React.PropTypes.string.isRequired,
index: React.PropTypes.number.isRequired,
我们把组件从装载,到渲染,再到卸载当做一次生命周期,也就是组件的生存状态从装载开始到卸载为止,期间可以根据属性的变化进行多次渲染。
生命周期的三种状态:
Mounting:装载,
Updating:渲染
Unmounting:卸载
componentWillMount(),组件开始装载之前调用,在一次生命周期中只会执行一次。
componentDidMount(),组件完成装载之后调用,在一次生命周期中只会执行一次,从这里开始就可以对组件进行各种操作了,比如在组件装载完成后要显示的时候执行动画。
componentWillUpdate(object nextProps, object nextState),组件属性更新之前调用,每一次属性更新都会调用
componentDidUpdate(object prevProps, object prevState),组件属性更新之后调用,每次属性更新都会调用
componentWillUnmount(),组件卸载之前调用
组件属性更改时会调用以下方法,在一次生命周期中可以执行多次:
componentWillReceiveProps(object nextProps),已加载组件收到新的参数时调用
shouldComponentUpdate(object nextProps, object nextState),组件判断是否重新渲染时调用
初始化第一个页面:
import SeatPageComponent from './SeatPageComponent';
import MainPageComponent from './MainPageComponent';
import TrainListComponent from './TrainListComponent';
class MainPage extends React.Component {
render() {
let defaultName = 'MainPageComponent';
let defaultComponent = MainPageC
&Navigator
// 指定默认页面
initialRoute={{ name: defaultName, component: defaultComponent }}
// 配置页面间跳转动画
configureScene={(route) =& {
return Navigator.SceneConfigs.VerticalDownSwipeJ
// 初始化默认页面
renderScene={(route, navigator) =& {
let Component = route.
// 将navigator作为props传递到下一个页面
return &Component {...route.params} navigator={navigator} /&
跳转到下一页面:
jumpToNext(){
const { navigator } = this.// 由上一个页面传递过来
if(navigator) {
navigator.push({
name: 'SeatPageComponent',
component: SeatPageComponent,// 下一个页面
返回上一个页面:
const { navigator } = this.
if(navigator) {
navigator.pop();
页面间通信
例如:从A页面打开B页面
A通过route.params将参数传递给B:
jumpToNext(){
const { navigator } = this.// 由上一个页面传递过来
if(navigator) {
navigator.push({
name: 'SeatPageComponent',
component: SeatPageComponent,// 下一个页面
params: { // 需要传递个下一个页面的参数,第二个页面使用this.props.xxx获取参数
title: this.state.title,
A通过route.params传递回调方法或者A的引用来让B将数据传回给A:
jumpToNext(){
const { navigator } = this.// 由上一个页面传递过来
if(navigator) {
let that =// this作用域,参见下文函数绑定
navigator.push({
name: 'SeatPageComponent',
component: SeatPageComponent,// 下一个页面
params: { // 需要传递个下一个页面的参数,第二个页面使用this.props.xxx获取参数
title: '测试',
getName: function(name) {that.setState({ name: name })}
const { navigator } = this.
if(this.props.getName){
this.props.getName('测试');
if(navigator) {
navigator.pop();
组件间通信
父组件--&子组件, 使用props,父组件向子组件传递props
class MainComponent extends React.Component{
return(&Label name="标题栏"&);
class Label extends React.Component{
return(&Text&{this.props.name}&/Text&);
子组件--&父组件, 父组件在创建子组件时传递回调方法
class MainComponent extends React.Component{
constructor(props) {
super(props);
this.state = {
name: '测试',
// 回调方法
getName(str){
this.setState({name:str});
return(&Label name="标题栏" getName={getName}/&);
class Label extends React.Component{
&TouchableOpacity onPress={()=&this._onPress()}&
&Text&点我,{this.props.name}&/Text&
&/TouchableOpacity&
_onPress(){
if(this.props.getName){
this.props.getName('测试')
非父子关系的组件,即没有任何嵌套关系的组件, 可以引入订阅源(, ),监听订阅事件。例如,在生命周期方法中addEventListener(),removeEventListener(),在合适时机setState()。
ECMAScript
ES6中函数的写法:
class Label extends React.Component{
doSomething(){
}// 不要使用逗号或者分号作为结尾
key:value形式定义函数的写法:
var Label = React.createClass({
doSomething:funation(){
},// 需要使用逗号作为结尾,不能使用分号
doSomething2:function(){
class Label extends React.Component{
sayHello(str){
console.log(str)
// 在onPress中使用箭头函数调用
// onPress={() =& this.sayHello('Hello')}
//onPress={sayHello('hello').bind(this)}
// onPress={print('hello',this)}
&TouchableOpacity onPress={() =& this.sayHello('Hello')}&
&Text&点我&/Text&
&/TouchableOpacity&
function print(str,this){
let that =// 注意这里this的生命周期
function say(str){
that.sayHello(str)// 此处不能再使用this
require,import:javascript的模块管理工具,管理各个模块之间的引用,解决javascript异步加载的问题,解决js写成多个文件后浏览器加载缓慢的问题。
JavaScript中没有private,public的概念
使用_开头的方法代表private方法,不适用则表示public方法
class Label extends Component{
// private 函数
_doSomething(){
// public 函数
doSomething(){
从事于Android客户端开发
在进行了2个星期的基础学习(Flexbox, React.js, JSX, JavaScript)之后,想通过一个实战项目来提高React Native的开发水平,于是找到了下面这个项目: 一. 项目介绍 这是我在学习贾鹏辉老师在慕课网上的一个很火的React Native...
自己最近的项目是基于react的,于是读了一遍react的文档,做了一些记录(除了REFERENCE部分还没开始读) 文章也可以直接访问我的前端网站来查看 quick start Tutorial 建立一个模块 我们可以使用React.createClass()来创建一个R...
原教程内容详见精益 React 学习指南,这只是我在学习过程中的一些阅读笔记,个人觉得该教程讲解深入浅出,比目前大多数教程专业、系统。 1.1 Introduction to React 1.1.1 What is React? React IS A JAVASCRIPT ...
JSX 知识准备 JSX 并不是一门全新的语言,仅仅是一个语法糖,允许开发者在javascript中编写XML语言。这样使用JavaScript来构建组件以及组件之间关系的应用,在代码层面显得更加清晰,而不再是使用JavaScript操作DOM来创建组件以及组件之间的嵌套关...
&一&编写Hello World React Native看起来很像React,只不过其基础组件是原生组件而非web组件。要理解React Native应用的基本结构,首先需要了解一些基本的React的概念,比如JSX语法、组件、state状态以及props属性。如果你已经...
尼采:更高级的哲人独处着,这并不是因为他想孤独,而是因为在他的周围找不到他的同类。 这是《天道》第一集中的一句话,一句想说没说出口的话! 《天道》这部电视剧,很久以前记得谁推荐过,前天再次被人推荐到,今天朋友圈又有人转载相关话题,我总觉得当某个东西在自己的身边频繁出现的时候...
妹子说自己不喜欢和男生聊天?不可能,不是你心理有问题(或者同性恋),就是身边男生太渣。看一看你身边的同学,你会发现,他们低着头噼里啪啦不停回复消息的人多半是男的,可能是男朋友,大多还是男性朋友,甚至网友。 那么为什么女生喜欢和男生聊天呢? 先来段官方的尝尝:从自然规律来讲,...
五年前,你来到我的世界!医生把粉粉嫩嫩的你放在我的胸口,那一刻,我感觉拥有了全世界,满心满眼都是你。把你放进眼里都不会疼。 带你的艰辛不言而喻,可是记忆力全是你美好的模样,还有你给我带来快乐的瞬间。 几个月的时候,你眨巴眨巴着小眼睛,好奇的打量着这个世界;长牙期,你流着口水...
#幸福是需要修出来的~每天进步1%~幸福实修09班~09.王文婷 ,银川# /30) 【幸福三朵玫瑰】 昨日3朵玫瑰2朵已采 今日3朵玫瑰 1.休息一下 2.整理行李 3.帮爱人整理沙龙主题提纲 【幸福实修30天目标】 1 隔天做面护 手护 2每天读英...英语语法大全_语法小贴士:状语从句中的省略问题_沪江英语
网页版学习工具
1. 在when,whenever,while,until,as soon as等引导的时间状语从句中,可以省略与主句中主语相同的主语和系动词或助动词。
When (he was) a child he ran wild. 他小的时候很不守规矩。
They were scolded whenever (they were) late for school.每次上学迟到,他们都要挨骂。
While (he was) in prison,he wrote his first novel.他在狱中写出了第一部小说。
As soon as (I am) on board I always feel sick. 我一上船就感到恶心。
2. 在if,unless,once等引导的条件状语从句中。
If (it is) not well organized,the meeting will be a failure.如果组织不好,会议就会失败。
Substances have no tendency to expand unless(they are) heated.除非受热,物质不会有膨胀的倾向。
Once (she was) inside her bedroom,she began to cry. 一走进卧室,她就开始哭。
3. 在where,wherever引导的地点状语从句中,可以省略主语和系动词或助动词。
Through long power lines,electricity goes where (it is) needed.电通过输电线输送到需要它的地方去。
4. 在than,as引导的比较状语从句中。
She works better than I (works). 她工作做得比我好。
I'd rather play football than (I'd rather) go swimming. 与其去游泳我还不如去踢足球。
Run as fast as you can (run). 你能跑多快就跑多快。
5. 在“the+比较级,the+比较级”的句型中。
The greater the force of action (is),the greater the force of reaction (is).作用力越大,反作用力也越大。
6. 在whatever,however引导的让步状语从句中,可以省略系动词。
He was determined to carry out the plan,whatever the cost (was).他决心执行计划,不管代价如何。
However difficult the task (may be),we must finish it on time.不管这任务有多难,我们都必须按时完成。
7. 在“no matter+疑问词”引导的让步状语从句中,可以省略系动词be和重复的主语。
Anyone,no matter who (he is),may point out my shortcoming.不管是什么人,谁向我指出缺点都行。
Anyone who commits a crime must be punished no matter what his position (is).任何犯罪的人都必须受到惩罚,不管他地位多高。
8. 在though,as though,as if引导的让步状语从句中。
Though (he is) tall, he is very weak in health. 他虽然长得高,但身体却很弱。
He went quickly out of the room as if (he was) in a hurry.他很快走出房间,好像很匆忙似的。
条件状语从句是比较常用的状语从句之一,又分为否定条件和肯定条件,否定条件最常见的引导词就是unless和if not,那么这两者又有什么异同呢?一起跟着沪江小编来看看吧!待解决问题
高分悬赏问题
最新已解决
一周热点问题
用户积分排名:
Powered by 英语答疑网 & ,Processed in 0.000000 second(s), 75 queries.
&加载中...英语语法大全,语法辞典,语法释疑,简明语法,语法学习,语法问题 - 旺旺英语教学网【图文】常见英语语法错误合集_百度文库
您的浏览器Javascript被禁用,需开启后体验完整功能,
享专业文档下载特权
&赠共享文档下载特权
&100W篇文档免费专享
&每天抽奖多种福利
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
常见英语语法错误合集
阅读已结束,下载本文到电脑
定制HR最喜欢的简历
你可能喜欢

我要回帖

更多关于 高中语法知识点总结 的文章

 

随机推荐