比较了半天VUE、Angular、React,最终选择React,下面从几个例子开始React的学习,先从单个的index.html,引用react.js开始

一.最简单的纯JS的代码

<!DOCTYPE html>
<html>
<head>
<title>react直接引用js</title>
<script src="https://cdn.staticfile.org/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdn.staticfile.org/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/javascript">
window.onload = function() {
var h1 = React.createElement("h1", null, "hello REACT!");
ReactDOM.render(h1, document.getElementById("root"));
};
</script> </body>
</html>

二、使用JSX的语法

JSX是React提供的语法,React会把JSX编译成JS,这个编译器使用了一个组件babel

<!DOCTYPE html>
<html>
<head>
<title>react直接引用js</title>
<script src="https://cdn.staticfile.org/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdn.staticfile.org/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<!-- 生产环境中不建议使用 -->
<script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
window.onload = function() {
ReactDOM.render(
<h1>Hello, REACT!</h1>,
document.getElementById("root")
);
};
</script>
</body>
</html>

三、通过组件的方式添加元素

<!DOCTYPE html>
<html>
<head>
<title>react直接引用js</title>
<script src="https://cdn.staticfile.org/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdn.staticfile.org/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<!-- 生产环境中不建议使用 -->
<script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
class Welcome extends React.Component{
render(){
return <h1>Hello, REACT!</h1>
}
} window.onload = function() {
ReactDOM.render(<Welcome />,
document.getElementById("root")
);
};
</script>
</body>
</html>

四、给组件添加属性功能

<!DOCTYPE html>
<html>
<head>
<title>react直接引用js</title>
<script src="https://cdn.staticfile.org/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdn.staticfile.org/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<!-- 生产环境中不建议使用 -->
<script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
class Welcome extends React.Component{
render(){
return <h1>Hello, {this.props.name}!</h1>
}
} window.onload = function() {
ReactDOM.render(<Welcome name='react16.3'/>,
document.getElementById("root")
);
};
</script>
</body>
</html>

react-01的更多相关文章

  1. [React] 01 - Intro: javaScript library for building user interfaces

    教学视频: http://www.php.cn/code/8217.html React 教程: http://www.runoob.com/react/react-tutorial.html 本篇是 ...

  2. [Full-stack] 快速上手开发 - React

    故事背景 [1] 博客笔记结合<React快速上手开发>再次系统地.全面地走一遍. [2] React JS Tutorials:包含了JS --> React --> Red ...

  3. [React] 08 - Tutorial: evolution of code-behind

    有了七篇基础学习,了解相关的知识体系,之后便是系统地再来一次. [React] 01 - Intro: javaScript library for building user interfaces ...

  4. [Code::Blocks] Install wxWidgets & openCV

    The open source, cross platform, free C++ IDE. Code::Blocks is a free C++ IDE built to meet the most ...

  5. Top 20 JavaScript Projects of 2017

    https://www.youtube.com/watch?v=SUMn8y3pi28 20. AngularJS 1 19. Passport 18. Pug 17. Socket.IO 16. J ...

  6. 本人SW知识体系导航 - Programming menu

    将感悟心得记于此,重启程序员模式. js, py, c++, java, php 融汇之全栈系列 [Full-stack] 快速上手开发 - React [Full-stack] 状态管理技巧 - R ...

  7. React 实践记录 01 组件开发入门

    Introduction 本文组成: Ryan Clark文章Getting started with React的翻译. 博主的实践心得. React由Facebook的程序员创建,是一个非常强大的 ...

  8. React Native 开发之 (01) 配置开发环境

    一 React Native React Native 是由Facebook发布的开源框架,着力于提高多平台开发的开发效率 —— 仅需学习一次,编写任何平台.(Learn once, write an ...

  9. React Native 学习-01

    React Native 学习 (学习版本 0.39) 一.环境配置 二.IDE选择 webstorm 1.webstorm配置 ①.首先是可以选择使用汉化包汉化.eu68 ②.安装插件和外部库. 由 ...

  10. react学习笔记-01

    1. HTML模板 Jsx是react的语法糖,最终会被编译成js语法.因此需要第三方库browser将jsx转换成js. 由于react 0.14版本之后,将react和react-dom拆分,所以 ...

随机推荐

  1. 吴恩达Machine Learning 第一周课堂笔记

    1.Introduction 1.1 Example        - Database mining        Large datasets from growth of automation/ ...

  2. Linux 内核的 Makefile

    Linux内核的配置系统的基本结构 Linux内核的配置系统由三个部分组成,分别是: 1.Makefile:分布在 Linux 内核源代码根目录及各层目录中,定义 Linux 内核的编译规则: 2.配 ...

  3. std::condition_variable::wait_until segment

    原因是使用了 -static 改为 -static-libstdc++ -static-libgcc

  4. 微信小程序 app.json文件配置

    https://developers.weixin.qq.com/miniprogram/dev/index.html  起步 https://developers.weixin.qq.com/min ...

  5. Pecan中api-paste.ini的解析

    在pecan中存在一个请求配置文件,定义服务启动程序app和过滤器filter,例如: [pipeline:main] pipeline = request_id sizelimit api-serv ...

  6. python 写入数据

    import sys reload(sys) sys.setdefaultencoding('utf8') import xlrd import xlwt book = xlrd.open_workb ...

  7. Windows7下安装、部署Weblogic和发布war项目

    安装 1 从官方下载安装包 链接 2 下载之后,放到 Java8\jdk1.8.0\bin目录下 3 打开cmd,输入 java -jar . 4 5 6 下面是我自定义的目录, 7 8 9 10 1 ...

  8. Python下划线简介

    Python中下划线的5种含义 分享一篇文章:The Meaning of Underscores in Python. 本文介绍了Python中单下划线和双下划线("dunder" ...

  9. netty(八) netty中自带channelhandler

    SslHandler:负责对请求进行加密和解密,是放在ChannelPipeline中的第一个ChannelHandler HttpClientCodec和HttpServerCodec:HttpCl ...

  10. Python·——进程1

    1.进程背景知识 顾名思义,进程即正在执行的一个过程.进程是对正在运行程序(的一个抽象). 进程的概念起源于操作系统,是操作系统最核心的概念,也是操作系统提供的最古老也是最重要的抽象概念之一.操作系统 ...