![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
使用React开发的项目所有遇到问题整合
在使用React开发的项目中所遇到的问题进行整理,方便以后出现同样问题好解决
慢吞吞的树懒
日复一日
展开
-
React 多个button默认给第一个button设置样式,autoFocus属性
代码:import React from "react";import '../../style/detailLift/HeaderDate.scss'export default class HeaderDate extends React.Component {state={ index:0//默认选中第一个} changeButton = (item,index) =>{ this.setState({index})//更新状态 this.props.se原创 2020-07-15 15:02:56 · 1902 阅读 · 1 评论 -
react中在componentDidMount生命周期函数中调用了多个this.setState报错
报错:超过最大更新深度。当组件在componentWillUpdate或componentDidUpdate中重复调用setState时,就会发生这种情况。React限制嵌套更新的数量,以防止无限循环。在componetDidMount中:componentDidMount(): void { var responeceDate:object =[] var pieName:string = 'dayElectric' if(this.props.uri === '/deta.原创 2020-07-14 00:07:48 · 3008 阅读 · 0 评论 -
React+TS中使用ref属性遇到的坑
开始代码:获取ref指定的当前元素对象在componentDidMount中可以this来获取这么写:componentDidMount(): void { const domWidth:any= this.domWidth.current this.setState({width:domWidth.clientWidth/2,height:domWidth.clientHeight}) }但是在static getDerivedStateFromProps中就不能采用this.的方原创 2020-07-13 23:56:25 · 8572 阅读 · 0 评论 -
recharts中Legend的margin属性设置无效
设置legend图例组件中的margin无效:.recharts-legend-item { transform: translateX(6em) translateY(-2em); }原创 2020-07-06 22:45:30 · 1516 阅读 · 0 评论 -
React中使用Less文件
本版本是:原创 2020-05-23 22:43:53 · 1868 阅读 · 0 评论 -
React中当src文件夹下文件想引用src文件夹外文件:报错
在src文件下的App.css文件中引入public文件夹中的图片时报错:原因:使用react—create-app构建的项目,当src文件夹下文件想引用src文件夹外文件因为官方限制问题会报以下错误解决:1:npm run eject 如果此项目使用了git,代码发生了更改得先add . 跟commit然后再使用eject命令。不然它会报错:This git repository has untracked files or uncommitted changes:(这个git仓库..原创 2020-05-23 17:25:45 · 4347 阅读 · 0 评论