一.项目创建(搭建带有typescript的)

1.安装命令

>npx create-react-app ts-with-react --typescript

2.npx是什么(优点,npm5.2版本以上有)?

1)避免安装全局模块

2)调用项目安装的内部模块

3.启动项目

>cnpm start

(React+TypeScript实战篇)一.项目构建

 

二.体验组件

1.在项目src目录下创建components目录然后新建Hello.tsx

(React+TypeScript实战篇)一.项目构建

2.在src目录下的App.tsx下引入使用

(React+TypeScript实战篇)一.项目构建

(React+TypeScript实战篇)一.项目构建

3.效果展示

(React+TypeScript实战篇)一.项目构建

 

三.组件优化

(React+TypeScript实战篇)一.项目构建

说明:优化后的组件,不传message属性的话,会使用默认的属性。如下图效果展示默认的。

(React+TypeScript实战篇)一.项目构建

(React+TypeScript实战篇)一.项目构建

 

相关文章:

  • 2022-12-23
  • 2021-10-28
  • 2021-05-19
  • 2021-12-24
  • 2022-12-23
  • 2021-05-01
  • 2022-12-23
  • 2021-05-22
猜你喜欢
  • 2021-06-28
  • 2022-01-04
  • 2021-10-15
  • 2021-10-01
  • 2021-10-12
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案