初学React:JSX语法
这是本人初学React做的学习笔记;讲的不是很深,只算是简单的进行介绍。
这是一个小系列。都是在同一个模板中搭建的,但是代码是不能正常执行的。
>>第一个组件.js
'use strick'
/*===========================JavaScript的XML语法========================*/
var CommentBox = React.createClass({
render:function () {
return (
<div className="CommentBox">
Hello, world!I am a CommentBox.
</div>
);
}
}); ReactDOM.render(
<CommentBox />,
document.getElementById('content')
); /*=====================以上JS语句将被翻译为;==========================*/
var CommentBox = React.createClass({displayName: 'CommentBox',
render: function() {
return (
React.createElement('div', {className: "CommentBox"},
"Hello, world!I am a CommentBox."
)
);
}
}); ReactDOM.render(
React.createElement(commentBox, null),
document.getElementById('content')
);
/*=============================撰写组件===================================*/ var CommentList = React.cracteClass({
render: function() {
return (
<div className="commentList">
Hello, React`s World!I am a Commentlist.I am form Lao Zhao.
</div>
);
}
}); var CommentForm = React.createClass({
render: function() {
return (
<div className="commentForm">
Hello React`s World!I am a CommentForm.I am from Lao Zhao.
</div>
); }
}); /*==============================更新组件===================================*/ var CommentBox = React.createClass({
render: function() {
return (
<div className="commentBox">
<h1>Comments</h1>
<CommentList />
<CommentForm />
</div>
);
}
}); /*==============================使用道具=======================================*/ var Comment = React.createClass({
render: function() {
return (
<div>
<h2 className="commentAuthor">
{this.props.author}
</h2>
{this.props.children}
</div>
);
}
}); /*===============================组件属性===========================================*/ var CommentList = React.createClass({
render: function() {
return (
<div className="commentList">
<Comment author="Zhao Gaosheng">This is one comment.</Comment>
<Comment author="Gaosheng">This is *another*comment.</Comment>
</div>
);
}
});
这里只是简单让大家感受一下JSX的语法氛围。
初学React:JSX语法的更多相关文章
- React JSX语法说明
原文:http://my.oschina.net/leogao0816/blog/379487 什么是JSX? 在用React写组件的时候,通常会用到JSX语法,粗看上去,像是在Javascript代 ...
- 2. React JSX语法及特点介绍
什么是JSX JSX 是一种类 XML 语言,全称是 JavaScript XML .React 可以不使用 JSX来编写组件,但是使用JSX可以让代码可读性更高.语义更清晰.对 Re ...
- React(JSX语法)-----JSX基本语法
JSX------HTML tags vs React Components: 1.To render a html tag,just use lower-case tag names in JSX; ...
- 学习 React(jsx语法) + es2015 + babel + webpack
视频学习地址: http://www.jtthink.com/course/play/575 官方地址 https://facebook.github.io/react/ 神坑: 1.每次this.s ...
- React(JSX语法)----动态UI
1.React honws how to bubble and capture events according to the spec,and events passed to your event ...
- React(JSX语法)----JSX拼写
注意:For DOM differences,such as the inline style attribute,check here. // bad: it displays "FIrs ...
- React(JSX语法)-----JSX属性
1. if you know all the propertities that you want to place on a component ahead of time,it is easy t ...
- 22-React JSX语法
React JSX语法 JSX只是一个语法糖,每一个XML标签都会被JSX转换工具转换成纯Javascript代码,当然你想直接使用纯Javascript代码写也是可以的,只是利用JSX,组件的结构和 ...
- Webstorm 不识别es6 import React from ‘react’——webstorm不支持jsx语法怎么办
2016-10-31更新 webstorm不支持es6语法怎么办? webstorm不支持jsx语法怎么办? 参考:webstorm不支持jsx语法怎么办 I spent ages trying to ...
随机推荐
- lintcode - 房屋染色
class Solution { public: /* * @param costs: n x 3 cost matrix * @return: An integer, the minimum cos ...
- 搭建element-ui Vue结构
1.安装淘宝镜像 npm install cnpm -g --registry=https://registry.npm.taobao.org 2.安装webpack cnpm install web ...
- Sublime Text 3 3126 安装+注册码
首先,到官网下载且安装,个人是安装版本的 https://www.sublimetext.com/3 接着,写入注册码.2016/11/26 亲测有效 —– BEGIN LICENSE —– Mich ...
- python3 reversed() 函数笔记
需要逆向循环序列的话,先正向定位序列,然后调用 reversed() 函数. for i in reversed(range(1, 10, 2)): print(i) 97531
- 8.Spring对JDBC的支持和事务
1.Spring对JDBC的支持 DAO : Spring中对数据访问对象(DAO)的支持旨在简化Spring与数据访问技术的操作,使JDBC.Hibernate.JPA和JDO等采用统一的方式访问 ...
- vue中this.$router.push() 传参
1 params 传参 注意⚠️:patams传参 ,路径不能使用path 只能使用name,不然获取不到传的数据 this.$router.push({name: 'dispatch', para ...
- Mybatis学习笔记16 - bind标签
1.${}拼串进行模糊查询,不安全 示例代码: 接口定义: package com.mybatis.dao; import com.mybatis.bean.Employee; import java ...
- sublime text2 for mac 实现json格式化
问题描述: 网上拿下来的一大段json格式的字符串,放到sublime上格式化成json的标准格式 数据截图如下: 解决问题: 网络上搜了一下,大部分都是说要装pretty json插件 先来看看自己 ...
- Unity GetComponentsInChildren
1 Component.GetComponentsInChildren 和 GameObject.GetComponentsInChildren 一样吗? API上解释一样. 2. //拿到游戏对象 ...
- Java基础14-多维数组
1.二位数组可以看成以数组为元素的数组 2.java中多维数组的声明和初始化一样,应该从高维到低维的顺序进行,例如 int[][] a=new int[3][]; a[0]=new int[2]; a ...