一切以官方文档为准
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>初学Reacttitle>
head>
<body>
<div id="app">div>
body>
html>
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>初学Reacttitle>
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin>script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin>script>
<link rel="stylesheet" href="indexCss.css" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
head>
<body>
<div id="app">div>
body>
<script type="text/babel" src="./main.js">script>
html>
function Demo(){
return <h1>Hello World</h1>
}
ReactDOM.render(<Demo/>,document.getElementById("app"))
const VDOM = (
<h1>hello word</h1>
)
ReactDOM.render(VDOM,document.getElementById("app"))
const e = React.createElement;
function Demo(){
let hello="wo"
return <h2 id={hello}>hello world</h2>
}
ReactDOM.render(<Demo/>,document.getElementById("app"))
const e = React.createElement;
function Demo(){
let hello="OK"
return <h2>hello world{hello}</h2>
}
ReactDOM.render(<Demo/>,document.getElementById("app"))
class添加样式写法
.Toggle_back{
background-color: orange;
}
function Demo(){
let hello="wo"
return <h2 className="Toggle_back" id={hello}>hello world</h2>
}
ReactDOM.render(<Demo/>,document.getElementById("app"))
const VDOM = (
<h1 style={{color:'red',fontSize: '29px'}}>hello word</h1>
)
ReactDOM.render(VDOM,document.getElementById("app"))
let data = ['亚丝娜','一岐日和','叶佳瑶']
/**
* 要区分: (js语句(代码))和(js表达式)
* 表达式: 一表达式会产生一个值,可以放在任何一个需要值的地方
* 下面都是表达式
* (1) a(变量名)
* (2) a+b
* (3) demo(1)
* (4) arr.map()
*/
const VDOM = (
<div>
<h1>Hello World</h1>
<ul>
{
for(let i=0;i<data.length;i++){
}
}
</ul>
</div>
)
ReactDOM.render(<Demo/>,document.getElementById("app"))
let data = [1,3,5,7,9]
let result = arr.map((num/*拿到的每一个值*/)=>{
//函数体
return num + 1
})
console.log(result)
const x = function test(){}
所以我们得这么写:
let data = ['亚丝娜','一岐日和','叶佳瑶']
const VDOM = (
<div>
<h1>Hello World</h1>
<ul>
{
data.map((item)=>{
return <li>{item}</li>
})
}
</ul>
</div>
)
ReactDOM.render(VDOM,document.getElementById("app"))
但是我们没有key(唯一值)所以我们
let data = ['亚丝娜','一岐日和','叶佳瑶']
const VDOM = (
<div>
<h1>Hello World</h1>
<ul>
{
data.map((item,index/*索引值*/)=>{
return <li key={index}>{item}</li>
})
}
</ul>
</div>
)
ReactDOM.render(VDOM,document.getElementById("app"))