1.基础语法

This commit is contained in:
shikong 2024-10-23 17:09:22 +08:00
parent 3ca95d76ba
commit b8a4c8f37e
Signed by: Shikong
GPG Key ID: BD85FF18B373C341
2 changed files with 154 additions and 13 deletions

93
.gitignore vendored
View File

@ -21,3 +21,96 @@
npm-debug.log* npm-debug.log*
yarn-debug.log* yarn-debug.log*
yarn-error.log* yarn-error.log*
### JetBrains+all template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# SonarLint plugin
.idea/sonarlint/
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### VisualStudioCode template
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
# Local History for Visual Studio Code
.history/
# Built Visual Studio Code Extensions
*.vsix

View File

@ -1,22 +1,70 @@
import logo from './logo.svg'; import React from "react";
// import logo from './logo.svg';
import './App.css'; import './App.css';
function App() { function App() {
// vue3 组合式 API
// React 必须大写 Pascal 命名 组件
function FnHello({name="Fn"}){
return <div>Hello world By {name}</div>
}
let com = FnHello({name:"obj"})
function FnHello2(){
return React.createElement("div", [], "Hello world By React.createElement")
}
// vue2 选项式 API
class ClassHello extends React.Component {
// eslint-disable-next-line no-useless-constructor
constructor(props) {
super(props);
}
render() {
return <div>Hello world By Class</div>
}
}
// React 不能直接渲染 js 对象
let obj = {
a: 1,
b: 2
}
// 如果是数组则依次遍历
let arr1 = [
1,
2,
3
]
let arr2 = [
FnHello({name:"arr1"}),
FnHello({name:"arr2"}),
FnHello({name:"arr3"}),
]
return ( return (
<div className="App"> <div className="App">
<header className="App-header"> <header className="App-header">
<img src={logo} className="App-logo" alt="logo" /> {/*<img src={logo} className="App-logo" alt="logo" />*/}
<p> <FnHello/>
Edit <code>src/App.js</code> and save to reload.
</p> <FnHello2/>
<a
className="App-link" <ClassHello/>
href="https://reactjs.org"
target="_blank" {com}
rel="noopener noreferrer"
> {JSON.stringify(obj)}
Learn React
</a> <br/>
{arr1}
{arr2}
</header> </header>
</div> </div>
); );