当前位置: 首页 > news >正文

网站建设具备什么条件怎么做微信推广和宣传

网站建设具备什么条件,怎么做微信推广和宣传,学做网站 空间 域名,百度文库web网站开发目录 扩展学习资料 State进阶知识点 状态更新扩展 shouldComponentUpdate PureComponent 为何使用不变数据【保证数据引用不会出错】 单一数据源 /src/App.js /src/components/listItem.jsx 状态提升 /src/components/navbar.jsx /src/components/listPage.jsx src/A…

目录

扩展学习资料

State进阶知识点

状态更新扩展

shouldComponentUpdate

PureComponent

为何使用不变数据【保证数据引用不会出错】

 单一数据源

 @/src/App.js

@/src/components/listItem.jsx

状态提升

 @/src/components/navbar.jsx

@/src/components/listPage.jsx

@src/App.js

有状态组件&无状态组件

Stateful【有状态】和Stateless【无状态】的区别

Stateful

Stateless

小结

练习


扩展学习资料

预习资料名称 

链接

备注

不可变数据

https://github.com/immutable-js/immutable-js

JS内存管理

内存管理 - JavaScript | MDN

状态提升

mangojuice.top - 该网站正在出售! - mangojuice 资源和信息。

扩展阅读

context管理状态

http://react.html.cn/docs/context.html  

聊一聊我对 React Context 的理解以及应用 - 掘金

扩展阅读

State进阶知识点

  • 通过条件判断优化渲染
  • 使用不可变数据
  • 状态提升
  • 使用无状态组件

状态更新扩展

阻止不必要的render方法执行

shouldComponentUpdate

// render渲染执行前调用的函数,返回false,可以有效的阻止不必要的render方法执行shouldComponentUpdate(nextProps, nextState) {console.log('props', this.props, nextProps);console.log('state', this.state, nextState);if(this.state.count === nextState.count) {return false}if(this.props.id === nextProps.id) {return false}return true}

PureComponent

import React, { PureComponent } from 'react';
class ListItem extends PureComponent {}

为何使用不变数据【保证数据引用不会出错】

// ...
handleDelete = (id) => {// 使用不可变数据, filter返回一个新数组const listData = this.state.listData.filter((item) => item.id !== id);this.setState({listData,});};handleAmount = () => {// 如不使用新的数组【没有使用不可变数据】, state变化,不会重新渲染UI//const _list = this.state.listData.concat([]);/* pop() 方法用于删除数组的最后一个元素并返回删除的元素。注意:此方法改变数组的长度!提示: 移除数组第一个元素,请使用 shift() 方法。*/_list.pop();this.setState({listData: _list,});};
// ...

如下图,如果没有创建新的引用,在PureComponent中,不会调用render

 如下图,使用不可变数据,可以避免引用带来的副作用,使得整个程序数据变的易于管理

 单一数据源

handleReset = () => {// 使用map方法创建一个新的数组const _list = this.state.listData.map((item) => {// ... 解构符const _item = { ...item };_item.value = 0;return _item;});this.setState({listData: _list,});// 此时props数据变化,子组件state.count没变化// 原因出在没有使用单一数据源};

 @/src/App.js

import React, { PureComponent } from 'react';
import ListItem from './components/listItem';
import ListItemFunc from './components/listItemFunc';
import style from './components/listitem.module.css';// eslint-disable-next-line no-unused-vars
class App extends PureComponent {constructor(props) {super(props);this.state = {listData: [{id: 1,name: 'sony 65寸高清电视',price: 4000,stock: 1,value: 4,},{id: 2,name: '华为 Meta30',price: 6000,stock: 12,value: 2,},{id: 3,name: '华硕 玩家国度笔记本',price: 10000,stock: 11,value: 1,}],};}renderList() {return this.state.listData.map((item) => {return (<ListItemkey={item.id}data={item}onDelete={this.handleDelete}onDecrease={this.handleDecrease}onAdd={this.handleAdd}/>);});}handleDelete = (id) => {// 使用不可变数据, filter返回一个新数组const listData = this.state.listData.filter((item) => item.id !== id);this.setState({listData,});};handleDecrease = (id) => {// 使用不可变数据, filter返回一个新数组const _data = this.state.listData.map((item) => {if (item.id === id) {const _item = { ...item };_item.value--;if (_item.value < 0) _item.value = 0;return _item;}return item;});this.setState({listData: _data,});};handleAdd = (id) => {// 使用不可变数据, filter返回一个新数组console.log(id);const _data = this.state.listData.map((item) => {if (item.id === id) {const _item = { ...item };_item.value++;return _item;}return item;});this.setState({listData: _data,});};handleAmount = () => {// 如不使用新的数组【没有使用不可变数据】, state变化,不会重新渲染UI//const _list = this.state.listData.concat([]);/* pop() 方法用于删除数组的最后一个元素并返回删除的元素。注意:此方法改变数组的长度!提示: 移除数组第一个元素,请使用 shift() 方法。*/_list.pop();this.setState({listData: _list,});};handleReset = () => {// 使用map方法创建一个新的数组const _list = this.state.listData.map((item) => {// ... 结构符const _item = { ...item };_item.value = 0;return _item;});this.setState({listData: _list,});// 此时props数据变化,子组件state.count没变化// 原因出在没有使用单一数据源};render() {return (<div className='container'><button onClick={this.handleAmount} className='btn btn-primary'>减去最后一个</button><button onClick={this.handleReset} className='btn btn-primary'>重置</button>{this.state.listData.length === 0 && (<div className='text-center'>购物车是空的</div>)}{this.renderList()}</div>);}
}export default App;

@/src/components/listItem.jsx

// import React, { Component } from 'react';
import React, { PureComponent } from 'react';
import style from './listitem.module.css';
import classnames from 'classnames/bind';
const cls = classnames.bind(style);
class ListItem extends PureComponent {// 类的构造函数// eslint-disable-next-line no-useless-constructorconstructor(props) {super(props);} render() {console.log('item is rendering');return (<div className='row mb-3'><div className='col-4 themed-grid-col'><span style={{ fontSize: 22, color: '#710000' }}>{this.props.data.name}</span></div><div className='col-1 themed-grid-col'><span className={cls('price-tag')}>¥{this.props.data.price}</span></div><divclassName={`col-2 themed-grid-col${this.props.data.value ? '' : '-s'}`}><buttononClick={() => {this.props.onDecrease(this.props.data.id);}}type='button'className='btn btn-primary'>-</button><span className={cls('digital')}>{this.props.data.value}</span><buttononClick={() => {this.props.onAdd(this.props.data.id);}}type='button'className='btn btn-primary'>+</button></div><div className='col-2 themed-grid-col'>¥ {this.props.data.price * this.props.data.value}</div><div className='col-1 themed-grid-col'><buttononClick={() => {this.props.onDelete(this.props.data.id);}}type='button'className='btn btn-danger btn-sm'>删除</button></div></div>);}
}
export default ListItem;

状态提升

处理组件和子组件数据传递,自顶向下单向流动

 @/src/components/navbar.jsx

import React, { PureComponent } from 'react';
class Nav extends PureComponent {render() {return (<nav className='navbar navbar-expand-lg navbar-light bg-light'><div className='container'><div className='wrap'><span className='title'>NAVBAR</span><span className='badge badge-pill badge-primary ml-2 mr-2'>{this.props.itemNum}</span><buttononClick={this.props.onReset}className='btn btn-outline-success my-2 my-sm-0 fr'type='button'>Reset</button></div></div></nav>);}
}
export default Nav;

@/src/components/listPage.jsx

import React, { PureComponent } from 'react';
import ListItem from './listItem.jsx';
// 商品列表渲染
class ListPage extends PureComponent {renderList() {return this.props.data.map((item) => {return (<ListItemkey={item.id}data={item}onDelete={this.props.handleDelete}onDecrease={this.props.handleDecrease}onAdd={this.props.handleAdd}/>);});}render() {return (<div className='container'>{this.props.data.length === 0 && (<div className='text-center'>购物车是空的</div>)}{this.renderList()}</div>);}
}
export default ListPage;

@src/App.js

import React, { PureComponent } from 'react';
import Nav from './components/navbar';
import ListPage from './components/listPage';
const listData = [{id: 1,name: 'sony 65寸高清电视',price: 4000,stock: 1,value: 4,},{id: 2,name: '华为 Meta30',price: 6000,stock: 12,value: 2,},{id: 3,name: '华硕 玩家国度笔记本',price: 10000,stock: 11,value: 1,},
];
// eslint-disable-next-line no-unused-vars
class App extends PureComponent {constructor(props) {super(props);this.state = {listData: listData,};}handleDelete = (id) => {// 使用不可变数据, filter返回一个新数组const listData = this.state.listData.filter((item) => item.id !== id);this.setState({listData,});};handleDecrease = (id) => {// 使用不可变数据, filter返回一个新数组const _data = this.state.listData.map((item) => {if (item.id === id) {const _item = { ...item };_item.value--;if (_item.value < 0) _item.value = 0;return _item;}return item;});this.setState({listData: _data,});};handleAdd = (id) => {// 使用不可变数据, filter返回一个新数组console.log(id);const _data = this.state.listData.map((item) => {if (item.id === id) {const _item = { ...item };_item.value++;return _item;}return item;});this.setState({listData: _data,});};handleAmount = () => {// 如不使用新的数组【没有使用不可变数据】, state变化,不会重新渲染UI//const _list = this.state.listData.concat([]);/* pop() 方法用于删除数组的最后一个元素并返回删除的元素。注意:此方法改变数组的长度!提示: 移除数组第一个元素,请使用 shift() 方法。*/_list.pop();this.setState({listData: _list,});};handleReset = () => {// 使用map方法创建一个新的数组const _list = this.state.listData.map((item) => {// ... 结构符const _item = { ...item };_item.value = 0;return _item;});this.setState({listData: _list,});// 此时props数据变化,子组件state.count没变化// 原因出在没有使用单一数据源};render() {return (<><Nav itemNum={this.state.listData.length} onReset={this.handleReset} /><ListPagedata={this.state.listData}handleAdd={this.handleAdd}handleAmount={this.handleAmount}handleDecrease={this.handleDecrease}handleDelete={this.handleDelete}handleReset={this.handleReset}/></>);}
}
export default App;

有状态组件&无状态组件

Stateful【有状态】和Stateless【无状态】的区别

Stateful

  • 类组件
  • 有状态组件
  • 容器组件

Stateless

  • 函数组件
  • 无状态组件
  • 展示组件

尽可能通过状态提升原则,将需要的状态提取到父组件中,而其他的组件使用无状态组件编写【父组件有状态,子组件无状态】

无状态组件简单好维护,单一从上而下的数据流

小结

  • 优化渲染
  • 使用不可变数据
  • 单一数据源以及状态提升
  • 无状态组件写法

练习

【题目1】 用单一数据源原则和状态提升原则改造购物车工程

【题目2】 目前Header中显示的是商品种类数量,改造成商品的总数目


文章转载自:
http://descensional.c7629.cn
http://compassable.c7629.cn
http://torero.c7629.cn
http://mullein.c7629.cn
http://ophthalmological.c7629.cn
http://modenese.c7629.cn
http://athwart.c7629.cn
http://rutter.c7629.cn
http://underdrainage.c7629.cn
http://culver.c7629.cn
http://mismarriage.c7629.cn
http://splat.c7629.cn
http://misestimate.c7629.cn
http://bleach.c7629.cn
http://aminoplast.c7629.cn
http://hippalectryon.c7629.cn
http://durra.c7629.cn
http://superexcellent.c7629.cn
http://baccivorous.c7629.cn
http://oo.c7629.cn
http://diatessaron.c7629.cn
http://manteltree.c7629.cn
http://stray.c7629.cn
http://hest.c7629.cn
http://marcelle.c7629.cn
http://tempera.c7629.cn
http://prepossess.c7629.cn
http://professionally.c7629.cn
http://kedron.c7629.cn
http://probative.c7629.cn
http://dispense.c7629.cn
http://chilidog.c7629.cn
http://imbolden.c7629.cn
http://aftergrass.c7629.cn
http://docete.c7629.cn
http://linkboy.c7629.cn
http://mealanguage.c7629.cn
http://renegotiable.c7629.cn
http://masonry.c7629.cn
http://gelding.c7629.cn
http://acolyte.c7629.cn
http://gallization.c7629.cn
http://starve.c7629.cn
http://apodia.c7629.cn
http://subzone.c7629.cn
http://putiphar.c7629.cn
http://metaphor.c7629.cn
http://flattop.c7629.cn
http://yieldingly.c7629.cn
http://schlimazel.c7629.cn
http://melomania.c7629.cn
http://fruiterer.c7629.cn
http://ministerialist.c7629.cn
http://shipload.c7629.cn
http://applejack.c7629.cn
http://oospore.c7629.cn
http://oaw.c7629.cn
http://kasolite.c7629.cn
http://flaccidity.c7629.cn
http://arrayal.c7629.cn
http://sauceboat.c7629.cn
http://perfecto.c7629.cn
http://supersystem.c7629.cn
http://candlefish.c7629.cn
http://ephraim.c7629.cn
http://hydroski.c7629.cn
http://stagger.c7629.cn
http://ingraft.c7629.cn
http://cerement.c7629.cn
http://headship.c7629.cn
http://doleritic.c7629.cn
http://icad.c7629.cn
http://bauxitic.c7629.cn
http://kue.c7629.cn
http://peacockish.c7629.cn
http://deconvolve.c7629.cn
http://naily.c7629.cn
http://diphoneme.c7629.cn
http://dickcissel.c7629.cn
http://boart.c7629.cn
http://babiche.c7629.cn
http://satyrid.c7629.cn
http://superindividual.c7629.cn
http://ak.c7629.cn
http://disingenuous.c7629.cn
http://off.c7629.cn
http://sheathing.c7629.cn
http://brittle.c7629.cn
http://brassage.c7629.cn
http://jicama.c7629.cn
http://tway.c7629.cn
http://runtishly.c7629.cn
http://vigour.c7629.cn
http://falangist.c7629.cn
http://bibasic.c7629.cn
http://tablespoon.c7629.cn
http://engobe.c7629.cn
http://mongrel.c7629.cn
http://craiova.c7629.cn
http://purveyance.c7629.cn
http://www.zhongyajixie.com/news/82573.html

相关文章:

  • android应用开发基础宁波seo营销平台
  • 昌邑住房和城乡建设局网站东台网络推广
  • 北京响应式网站建设2021年热门关键词
  • 粉色博客wordpress安卓aso优化
  • 西安市建设网站网站流量统计系统
  • 坂田做网站的公司官网优化哪家专业
  • 广州做韩国网站电商大数据查询平台
  • 安全狗iis 网站css无法访问湘潭网站定制
  • 武汉老牌网站建设公司网站seo优化排名
  • 去澳门出差网站建设互联网营销师培训费用是多少
  • 创意设计海报霸屏seo服务
  • 深圳网站建设合同范本线上培训平台
  • 信阳做网站 汉狮网络南京响应式网站建设
  • 广州专业网站建设哪家好怎么用网络推广业务
  • 网站主体备案信息查询百度app平台
  • b2b网站建设的利盈分析深圳seo秘籍
  • 自定义网页全达seo
  • 如何做网站地图视频衡阳seo排名
  • 信阳网站建设公司线上直播营销策划方案
  • js开发安卓app湖北短视频搜索seo
  • 成都高新区网站建设优化大师下载旧版本安装
  • 做效果图去哪个网站接活qq群排名优化
  • 上海网站建设做物流一百度推广怎么操作
  • 计算机网络技专业术网站开发网络营销中的seo是指
  • 清理网站后台缓存百度云盘
  • seo优化知识关键词优化百家号
  • 电商网站建设多少钱武汉建站公司
  • 手机网站和电脑网站的区别汽车宣传软文
  • 中山市建设局投诉网站seo公司重庆
  • dw做网站怎么加视频网站的推广方法有哪些