react
文章平均质量分 92
codeXml
web developer
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
react中动态添加style和className
1、动态添加style<div style={{height: this.state.is_makeup===0 ? "100%" : "50%"}}</div>添加多个样式<div style={{display: (index===this.state.currentIndex) ? "block" : "none", color:"red"}}>此标签是...原创 2020-03-04 09:53:15 · 2080 阅读 · 0 评论 -
react中使用echarts
1、安装npm install --save echarts-for-react2、引入import React from 'react';import ReactEcharts from 'echarts-for-react';3、使用在react中使用echarts很简单,只需要将option中的代码放到react的getOptions方法中就就OK了,配置参数可以参看官网,ec...原创 2020-02-19 11:33:23 · 456 阅读 · 0 评论 -
html2canvas生成的图片偏移不完整
问题背景:生成的图片在一个弹窗里面,如果页面没有滚动条就是正常的,但是一旦出现滚动条并且页面发生滚动时html2canvas绘制成的图片就会偏移出对应滚动高度的白边,如下:解决办法:楼主查了很多资料,也用了很多方法都没能解决这个问题,一气之下打算研究研究html2canvas的配置参数,果不其然,在配置参数RenderOptions下找到如下配置眼尖的楼主立马发现了scrollY这个东西。...原创 2020-02-16 17:03:34 · 8057 阅读 · 2 评论 -
react-router-dom路由模块化
1、先看一下未模块化的路由配置,有哪些地方是可以提出去的import React from 'react'import '../css/index.css'import { BrowserRouter as Router, Route, Link} from 'react-router-dom'/********************这一块是可以单独提出去的 start********...原创 2020-02-04 18:35:25 · 690 阅读 · 0 评论 -
react生命周期
1、当页面加载依次触发:2、当数据更新依次触发:注意:只有当shouldComponentUpdate返回值为true才会触发更新3、当页面销毁时触发:componentWillUnmount4、当来自父组件的值在父组件发生更新时依次触发:componentWillReceiveProps、shouldComponentUpdate、componentWillUpdate、ren...原创 2020-01-23 17:28:19 · 448 阅读 · 0 评论 -
react中的父子组件通信
1、父组件获取子组件的数据及调用子组件的方法step 1: 在父组件引入子组件,并通过ref获取子组件实例例:<Header ref='childMethod'/>step 2: 在父组件方法中通过refs获取子组件的方法或数据例:this.refs.childMethod.getchildMethod() / this.refs.childMethod.state.dat...原创 2020-01-23 13:58:55 · 301 阅读 · 0 评论 -
react实现数据的双向绑定
大概思路:1、当输入框的值发生改变时触发事件iptchange2、在iptchange内将输入框的值赋值到state3、点击按钮触发事件clickfun4、在clickfun内获取输入框的值方法一: 通过event.traget获取输入框的值(event.target.value)import React from 'react'class Methods extends Re...原创 2020-01-16 15:59:24 · 368 阅读 · 0 评论 -
TypeError: Cannot read property 'state' of undefined
问题描述:react组件中的方法获取state中的值时报错:TypeError: Cannot read property ‘state’ of undefined解决办法:方法一(在constructor中绑定this到函数):this.funOne = this.funOne.bind(this);import React , {Component} from 'react'; c...原创 2020-01-16 14:27:06 · 6223 阅读 · 0 评论 -
react渲染列表的四种方式
方式一(直接在html中渲染):import React from 'react'class News extends React.Component { constructor(props) { super(props); // 用于父子组件传值 this.state = { info: [{ ...原创 2020-01-16 11:25:23 · 5626 阅读 · 0 评论
分享