
前端开发工程师
cat10month
这个作者很懒,什么都没留下…
展开
-
react setState执行两次的原因
setstate原创 2023-02-24 10:19:17 · 285 阅读 · 0 评论 -
解释什么叫闭包
闭包原创 2023-02-14 15:24:09 · 105 阅读 · 0 评论 -
`super()` is only valid inside a class constructor of a subclass.解决方法
react问题原创 2023-01-17 16:12:49 · 454 阅读 · 0 评论 -
typescript omit类型
omit原创 2022-12-05 16:32:18 · 350 阅读 · 0 评论 -
本地运行前端包
http-server原创 2022-11-15 10:43:31 · 754 阅读 · 0 评论 -
CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
react内存溢出原创 2022-11-02 13:43:53 · 235 阅读 · 0 评论 -
React.Fragment的作用
React.Fragment原创 2022-10-31 11:51:35 · 133 阅读 · 0 评论 -
函数组件内直接写接口调用导致死循环的问题
接口调用死循环原创 2022-10-26 15:31:08 · 209 阅读 · 0 评论 -
echarts折线图的symbol自定义样式
折线图拐点自定义样式原创 2022-09-14 17:53:22 · 4265 阅读 · 0 评论 -
css transform:scale缩放后位置偏移问题解决
css相关问题原创 2022-09-01 14:44:54 · 11230 阅读 · 0 评论 -
Modal.confirm不能应用ConfigProvider的prefixCls解决方法
Modal调用方法没有全局样式的解决方法原创 2022-08-19 13:55:26 · 1232 阅读 · 0 评论 -
查看css样式的迅速定位方法
css样式相关原创 2022-06-25 15:13:57 · 778 阅读 · 0 评论 -
类型“undefined”不能用作索引类型
interface PointLayerType { type?: string, url?: string, MapZoom?: any; cameraList?: any[]}const ZoomRatio = { 0: 0.75, 1: 0.95, 2: 1.15, 3: 1.35, 4: 1.55, 5: 1.75,}; const width = 35 * ZoomRatio[MapZoom];//报错 类型“undefined”不能用作索引类型原创 2022-05-03 23:13:26 · 4921 阅读 · 0 评论 -
react组件内引入其他外部js
import './app/lib-generate-test-usersig.min.js';const generator: any = new LibGenerateTestUserSig(sdkAppId, SECRETKEY, EXPIRETIME); const userSig = generator.genTestUserSig(userId);原创 2022-04-22 11:08:34 · 3865 阅读 · 0 评论 -
Absolute imports should come before relative imports 的解决方案
绝对引入必须要在相对引入之前例如`import "../../utils"import _ from 'lodash'会报错,因为相对引入在绝对引入之前解决方案:1.更改引入顺序import _ from 'lodash'import "../../utils"2.更改eslintrc.jsmodule.exports = { "extends": ["taro/react"], "rules": { "react/jsx-uses-react": "off",原创 2022-03-13 14:01:52 · 1783 阅读 · 0 评论 -
styled引起的antd的bug
使用styled渲染antd组件,导致每次点击组件都会重新渲染,出现日期范围选择框无法重新选择,解决方法:const StyledDateRangePicker = useMemo(() => { return WrapDateRangePicker; }, [config?.value, prefixCls]);使用useMemo不渲染styled组件...原创 2022-03-08 17:09:34 · 213 阅读 · 0 评论 -
css字体小于12px
<span style={{display:'inline-block',fontSize:'16px',zoom:'0.5',color: '#798295'}}>新能源</span>=> 想要实现字体大小为8px,用16px缩放0.5倍即可设置zoom:0.5原创 2021-12-02 15:09:26 · 858 阅读 · 0 评论 -
对象数组遍历获取值数组
const demoImages = [ {url:'https://images.unsplash.com/photo-1620476214170-1d8080f65cdb?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=3150&q=80', desc:'行驶证照片'}, {url:'https://images.unsplash原创 2021-11-30 17:28:10 · 548 阅读 · 0 评论 -
event的typescript类型
const handleClose = (event: React.MouseEvent<Document, MouseEvent>) => { if (anchorRef && anchorRef.current && event.target instanceof Node && anchorRef.current.contains(event.target)) { return } setOpen原创 2021-11-19 10:55:57 · 2892 阅读 · 0 评论 -
“yield“ 表达式隐式导致 “any“ 类型,因为它的包含生成器缺少返回类型批注。ts(7057)
redux-saga 使用yield报ts类型错误解决方案:*getPlanById( { payload: id }: any, { call, put, select }: any ) { const res: any = yield call(planViewService.apiGetPlanById, id); if (res.code === 0) { message.info('加载数据成功'); } else {原创 2021-11-17 16:22:15 · 4636 阅读 · 0 评论 -
react-router /路径指向想要的路由
<Switch> <Route exact={true} path="/" render={()=> <Redirect to="/organization/all" push />}/> <Route path="/repository" children={() => ( <Switch>原创 2021-10-29 14:04:37 · 383 阅读 · 0 评论 -
通过一个数组去过滤另一个数组的数据
const userInfo = [ { id:1, name:"张三", age:25, sex:"male" }, { id:2, name:"李四", age:18, sex:"male" }, { id:3, name:"王五", age:21, sex:"female"原创 2021-09-08 17:12:11 · 921 阅读 · 0 评论 -
git 合并相关
git分支合并分支比如dev1合并dev2的代码直接在dev1里git merge dev2如果有冲突,解决冲突之后提交代码如果dev2后续有新的更改git merge dev2的时候会遇到然后重新git commit即可原创 2021-09-01 16:19:44 · 127 阅读 · 0 评论 -
react hooks子组件通知父组件更新其他子组件的方法
const [isRefresh, setIsRefresh] = useState(false); useEffect(() => { isRefresh && setTimeout(() => setIsRefresh(false)); }, [isRefresh]); const updateChild = () => { setIsRefresh(true); } return ( !isRefresh &a..原创 2021-08-24 15:54:55 · 2619 阅读 · 0 评论 -
useRef作用
react 定时器修改状态需要用到useRefconst like = useRef(0);setInterval(()=>{ console.log(like.current)},1000)采用useRef,作为组件实例的变量,保证获取到的数据肯定是最新的。返回一个可变的ref对象,该对象只有个current属性,初始值为传入的参数(initialValue)。返回的ref对象在组件的整个生命周期内保持不变当更新current值时并不会re-render,这是与useState不同原创 2021-07-23 10:21:07 · 1981 阅读 · 0 评论 -
RangePicker组件设置时间范围只能选择一年
const [dates, setDates]:any = useState(); const [hackValue, setHackValue]:any = useState(); const [value, setValue]:any = useState([ moment(moment(new Date()).subtract("days", 7).format("YYYY-MM-DD")), moment(moment(new Date()).format(dateForma原创 2021-06-29 11:16:09 · 4979 阅读 · 1 评论 -
react websocket接受消息推送
//编写ReactWebsocket组件import React from 'react';import Websocket from 'react-websocket';interface ReactWebsocketProps { onMessage:(data:any)=>void; onOpen:(data:any)=>void; onClose:()=>void; url:any; reconnect:any; debug:a原创 2021-06-11 16:23:50 · 1305 阅读 · 3 评论 -
antd popOver组件样式修改当前页面样式
修改popOver组件的样式的时候发现定义了className不起作用,antd的样式覆盖不了原因:不支持className,而是tooltip的overlayClassName<Popover content={renderContent()} title={''} overlayClassName={styles.pop} trigger={'click'}> <div className={styles.tipIcon}/></Popover>原创 2021-04-30 13:34:25 · 7882 阅读 · 3 评论 -
语音播报刷新页面不能播报问题的原因
使用SpeechSynthesisUtterance进行语音播报文字的时候,发现刷新浏览器不能播放声音的问题原因:浏览器对于语音,视频等会有限制,不能允许直接播放,必须进行至少一次点击事件解决方案:随意点击页面上的内容,即可重新触发...原创 2021-04-15 17:29:09 · 2928 阅读 · 0 评论 -
js将数组中的某一条替换为另一条数据
let list = [ { id: 1, name: "zhangsan" }, { id: 2, name: "lisi" }, { id: 3, name: "wangwu" }];let newItem = { id: 2, name: "xiaoming", sex: "female" }; list = list.map(t => { return t.id === newItem.id ? newItem : t;}原创 2021-03-15 15:29:44 · 4905 阅读 · 1 评论 -
小程序调用高德地图
https://elemefe.github.io/react-amap/components/about使用react-amap原创 2021-03-08 14:47:59 · 989 阅读 · 0 评论 -
antd-mobile的ListView进入详情页面再返回列表页面滚动到原来item位置
<ListView dataSource={dataSource.cloneWithRows(data)} ref={node => handelRef(node)} initialListSize={sessionStorage.getItem('dataLength') ? sessionStorage.getItem('dataLength') * 1 : 10} renderF原创 2021-03-05 17:28:12 · 1136 阅读 · 0 评论 -
Select组件模糊搜索选项
const handleSearch = (input: any, option: any) => { if (option && option.props && option.props.children) { return ( option.props.children === input || option.props.children.indexOf(input) !== -1 ); } e原创 2021-03-01 17:15:26 · 428 阅读 · 0 评论 -
antd样式覆盖问题
css用body套一下所有样式body{ .form { margin: 20px; .flexRow { display: flex; flex-direction: row; } .inputOther { width: 150px; margin-left: 10px; margin-right: 10px; text-align: center; border-top:原创 2021-03-01 17:03:03 · 2253 阅读 · 0 评论 -
react当前页面插入外部script
componentDidMount() { const script = document.createElement("script"); script.src = "/scripts/xxx.js"; script.async = true; document.body.appendChild(script); }原创 2021-01-25 14:49:06 · 1056 阅读 · 0 评论 -
antd tab切换刷新tab内组件的方法
复制代码onChange =(key)=> { this.setState({ activeKey:key })}...<Tabs onChange={this.onChange}> <TabPane key='1'> { aciveKey == '1' ? <Query/> : null } </TabPane> <TabPane key='2'> { aciveKey ==原创 2020-12-31 13:54:05 · 7186 阅读 · 0 评论 -
react点击事件里获取this.props.xx报错
报错原因:点击事件获取this.props.xx报错是由于点击事件没有绑定到dom元素上 handleBatchCancel(){ console.log('handleBatchCancel') console.log(this.props.checkedList)//报错 }解决方案:用bind绑定constructor(props: any) { super(props); this.handleBatchCancel = this.handleBatchC原创 2020-12-10 10:59:23 · 633 阅读 · 0 评论 -
react中window.addEventListener和window.removeEventListener的使用
写代码过程中,发现在react的tsx中绑定原生事件window.addEventListener当前页面可以监听到事件,其他页面也可以监听到事件,这就会产生问题,比如A页面监听滚动事件,B页面不需要监听滚动事件,但是B页面也会触发,此时就会产生bug。正确做法是在A页面绑定事件后,页面卸载的时候清除监听事件。 constructor(props) { super(props); this.scrollHandler = this.handleScroll.bind(this);原创 2020-11-29 15:07:03 · 5969 阅读 · 0 评论 -
antd-mobile Tabs组件下划线居中问题
<Tabs tabs={tabList} initialPage={0} // page={tabIndex} tabBarPosition="top" tabBarBackgroundColor={"transparent"} tabBarActiveTextColor={"#3A3A47"} tabBarInactiveTextC原创 2020-11-29 12:03:26 · 3536 阅读 · 0 评论 -
react上传附件,视图没有更新的解决方案
场景:在上传图片列表的时候,点击图片右上角的x删除已上传的图片块的时候,使用hooks的setFileList(files),发现视图并不会更新,图片块还在const [fileList,setFileList] = useState([])const deleteImgItem = (index,files) => { files.splice(index,1); setFileList(files) }解决方案:将setFileList(files原创 2020-10-15 15:34:19 · 525 阅读 · 0 评论