需要理解的概念有:
脚手架安全事故案例,reac脚手架
创建项目并启动
第一步,全局安装:npm i -g create-react-app
第二步,切换到想创项目的目录,使用命令:create-react-app hello-react(或者直接npx create-react-app hello-react 不用进行全局安装)
第三步,进入项目文件夹:cd hello-react
第四步,启动项目:npm start
需要理解的概念有:
需要理解的概念有:
运行命令:npx jest App.test.js --watch
报的错误是jsx的解析目前不支持
可以配置babel.config.js,并且安装cnpm i @babel/plugin-transform-runtime @babel/preset-flow -D再测试
module.exports = function (api) {const presets = ['@babel/preset-env', '@babel/preset-react', '@babel/preset-flow'];const plugins = ['@babel/plugin-transform-runtime'];api.cache(false);return {presets,plugins,};
};
则发现不再报jsx的解析不成功,而是报svg文件格式不支持解析了。所以,可以利用test进行项目文件的逐一测试操作。
如果查看性能指标:
1.给reportWebVitals添加console.log打印输出
2.给chrome安装查看性能的插件:Web Vitals
只留index.js(入口文件)与App.js(主组件)
需要理解的概念有:
<!DOCTYPE html>
<html lang="en"><head><meta charset="utf-8" /><!-- 引入public里的资源最好用%PUBLIC_URL% --><link rel="icon" href="%PUBLIC_URL%/favicon.ico" /><!-- 开启理想视口 --><meta name="viewport" content="width=device-width, initial-scale=1" /><!-- 更改浏览器地址栏颜色--但仅适用于安卓手机,且是谷歌原厂安卓系统 --><meta name="theme-color" content="#000000" /><!-- 介绍网站(给爬虫看) --><meta name="description" content="Web site created using create-react-app" /><!-- 控制ios系统主屏图标 --><link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /><!-- 应用加壳配置文件,最后学习uniApp加壳打包的时候将再次了解 --><link rel="manifest" href="%PUBLIC_URL%/manifest.json" /><title>React App</title>
</head><body><!-- 浏览器禁用js将显示以下代码内容 --><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div>
</body></html>
需要理解的概念有:
需要理解的概念有:
入口文件:index.js
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(<App />, document.getElementById('root'));
主组件:App.js
// 函数式组件中没有引入React
// 引入默认对象
import Weather from './components/Weather';
function App() {return (<div>App<Weather /></div>);
}export default App;
子组件:
// 引入默认对象与引入部分导出的对象
import React, { Component } from 'react';// 将类(组件)默认接口暴露
export default class Weather extends Component {state = {isHot: true,};render() {const { isHot } = this.state;return (<div>今天天气{isHot ? '炎热' : '凉爽'}<button onClick={this.changeWeather}>天气变化</button></div>);}changeWeather = () => {this.setState({isHot: !this.state.isHot,});};
}
需要理解的概念有:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-MYFX0zKH-1623239362281)(http://qn.chinavanes.com/qiniu_picGo/image-20210516144652022.png)]
components/Weather/index.js
import React, { Component } from 'react';
import './index.css';
export default class Weather extends Component {state = {isHot: true,};render() {const { isHot } = this.state;return (<div className='title'>今天天气{isHot ? '炎热' : '凉爽'}<button onClick={this.changeWeather}>天气变化</button></div>);}changeWeather = () => {this.setState({isHot: !this.state.isHot,});};
}
components/Weather/index.css
.title {color: red
}
components/Hello/index.js
const Hello = (props) => {return <div className='title'>Hello World</div>;
};export default Hello;
components/Hello/index.css
/* 暂不设置样式 */
src/App.js
import Weather from './components/Weather';
import Hello from './components/Hello';function App() {return (<div>App<Weather /><Hello /></div>);
}export default App;
components/Hello/index.css
.title {color: blue
}
import React, { Component } from 'react';
// 需要将index.css修改成index.module.css
import weather from './index.module.css';
export default class Weather extends Component {state = {isHot: true,};render() {const { isHot } = this.state;return (<div className={weather.title}>今天天气{isHot ? '炎热' : '凉爽'}<button onClick={this.changeWeather}>天气变化</button></div>);}changeWeather = () => {this.setState({isHot: !this.state.isHot,});};
}
需要理解的概念有:
需要理解的概念有:
() => {
this.setState({
isHot: !this.state.isHot,
});
};
}
# 八 vscode 中 react 插件的安装需要理解的概念有:- 优化开发工具,提升开发速度[外链图片转存中...(img-HGnCssqT-1623239362283)]# 九 组件化编码流程需要理解的概念有:- 拆分组件:拆分界面,抽取组件
- 实现静态组件:使用组件实现静态页面效果
- 实现动态组件- 3.1 动态显示初始化数据- 3.1.1 数据类型- 3.1.2 数据名称- 3.1.3 保存在哪个组件?- 3.2 交互(从绑定事件监听开始)
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态