@@ -6,7 +6,7 @@ Visual Studio Code(简称 VSCode)是由微软开发的一款现代化、轻
66
77VSCode 可以在 Windows、macOS 和 Linux 操作系统上运行,为开发者提供了一个统一的开发环境。
88
9- [ 官网地址] ( https://code.visualstudio.com/ )
9+ [ 官网地址] ( https://code.visualstudio.com/ )
1010
1111## Node.js 运行环境
1212
@@ -20,9 +20,9 @@ Node.js 提供了一个独立于浏览器的运行环境 (runtime environment)
2020首先找个你想创建项目的文件夹,运行下面的命令,输入项目名称,选择 React 然后是 TypeScript。
2121
2222``` bash
23- $ npm create vite@latest
24- ```
23+ npm create vite@latest
2524
25+ ```
2626
2727## Ant Design 组件资源
2828
@@ -35,41 +35,52 @@ Ant Design 还提供了不少图标资源可以使用。
3535安装:
3636
3737``` bash
38- $ npm install antd
38+ npm install antd
39+
3940```
4041
4142## 实操开始
4243
4344** 项目简介** :点击按钮次数加1,并可以用输入框改变标题。
4445
4546** 步骤** :
47+
46481 . ** 引入AntD组件** :
4749
4850将import的代码放在App.tsx的最上面
4951
50- ``` App.tsx
52+ ::: code-group
53+
54+ ``` tsx [App.tsx]
5155import { Button } from " antd" ;
5256import { Input } from " antd" ;
5357import { Space } from ' antd' ;
5458```
5559
60+ :::
61+
56622 . ** 选择自己喜欢的按钮样式** :
5763
5864具体例子如下,可自行前往AntD官网学习。
5965
60- ``` App.tsx
61- <Button color = " primary" variant = " solid" >
62- 按钮一枚
63- </Button >
66+ ::: code-group
67+
68+ ``` tsx [App.tsx]
69+ <Button color = " primary" variant = " solid" >
70+ 按钮一枚
71+ </Button >
6472```
6573
74+ :::
75+
66763 . ** 使用useState** :
6777
6878引入count和setCount并在按钮组件中使用onClick
6979
70- ``` App.tsx
80+ ::: code-group
7181
72- function App() {
82+ ``` tsx [App.tsx]
83+ function App() {
7384 const [count, setCount] = useState (0 )
7485
7586 return (
@@ -85,22 +96,30 @@ import { Space } from 'antd';
8596}
8697```
8798
99+ :::
100+
881014 . ** 加入输入框** :
89102
90103将Input和Button放入Space之中,这三个都是AntD的组件。
91104
92- ``` App.tsx
93- <Space.Compact style = { { width: ' 100%' }} >
94- <Input placeholder = " 这是一个输入框" />
95- <Button color = " primary" variant = " solid" }>提交</Button>
96- </Space.Compact>
105+ ::: code-group
106+
107+ ``` tsx [App.tsx]
108+ <Space.Compact style = { { width: ' 100%' }} >
109+ <Input placeholder = " 这是一个输入框" />
110+ <Button color = " primary" variant = " solid" > 提交 </Button >
111+ </Space.Compact >
112+
97113```
98114
115+ :::
991165 . ** 实现改标题功能** :
100117
101118下面是完整的代码
102119
103- ``` App.tsx
120+ ::: code-group
121+
122+ ``` tsx [App.tsx]
104123import { useState } from ' react'
105124import ' ./App.css'
106125import { Button } from " antd" ;
@@ -124,7 +143,6 @@ function App() {
124143 <Input placeholder = " 改标题" onChange = { (e ) => setNewTitle (e .target .value )} />
125144 <Button color = " primary" variant = " solid" onClick = { () => setBT ((bt ) => newTitle )} >提交</Button >
126145 </Space.Compact >
127-
128146 </>
129147 )
130148}
@@ -133,13 +151,11 @@ export default App
133151
134152```
135153
154+ :::
155+
136156在终端里输入下面指令试试
137157
138158``` bash
139- $ npm run dev
140- ```
141-
142-
143-
144-
159+ npm run dev
145160
161+ ```
0 commit comments