05案例 每隔0.2s颜色变淡###

componentDidMount表示组件已经挂载,可以进行DOM操作###

import React, { Component } from "react";
export default class Life extends Component {
state={
opacity:1
} componentDidMount(){ //声明周期 表示组件已经挂载了
let { opacity } = this.state //解构
setInterval(() => {
opacity -= 0.1;
if (opacity <= 0) {
opacity = 1
} this.setState({
opacity
})
console.log(opacity); }, 200); } render(){
let { opacity } = this.state //结构
// 因为state已发生改变 render就会执行
// 所以 当 opacity的值发生改变 render函数就会执行 setTimeout就变成了每个0.2s循环一次
// render 一上来就会执行 状态改变就会执行
return(
<div style={{ opacity }}> React学不会了 怎么办</div>
)
}
}

使用

ReactDOM.unmountComponentAtNode(document.getElementById("root")) 报错

因为你没有引用

import ReactDOM from 'react-dom'

React每隔0.2s颜色变淡 之生命周期 ,componentDidMount表示组件已经挂载的更多相关文章

  1. React每隔0.2s颜色变淡 之settimeOut变成setInterval

    案例 每隔0.2s颜色变淡 公共数据是放在state中的哦! 代码如下 import React, { Component } from "react"; import { set ...

  2. React 学习笔记(1) 基础语法和生命周期

    参看:视频地址 简单搭建一个react-cli: 2. React.createElement() 将object转化为 React语法 import React from 'react' impor ...

  3. IIS 7.0 的 ASP.NET 应用程序生命周期概述(转载)

    IIS 7.0 的 ASP.NET 应用程序生命周期概述更新:2007 年 11 月本主题介绍在 IIS 7.0 集成模式下运行以及与 IIS 7.0 或更高版本一起运行的 ASP.NET 应用程序的 ...

  4. IIS 7.0 的 ASP.NET 应用程序生命周期概述

    文章:IIS 7.0 的 ASP.NET 应用程序生命周期概述 地址:https://msdn.microsoft.com/zh-cn/library/bb470252(v=vs.100).aspx ...

  5. IIS 5.0 和 6.0 的 ASP.NET 应用程序生命周期概述

    本主题概述 ASP.NET 应用程序的生命周期,列出了重要的生命周期事件,并描述了您编写的代码将如何适应于应用程序生命周期.本主题中的信息适用于 IIS 5.0 和 IIS 6.0.有关 IIS 7. ...

  6. react学习(三)之生命周期/refs/受控组件 篇

    挂载/卸载 //在类组件中 class Clock extends React.Component { constructor(props) { super(props); this.state = ...

  7. vue2.0项目实战(4)生命周期和钩子函数详解

    最近的项目都使用vue2.0来开发,不得不说,vue真的非常好用,大大减少了项目的开发周期.在踩坑的过程中,因为对vue的生命周期不是特别了解,所以有时候会在几个钩子函数里做一些事情,什么时候做,在哪 ...

  8. SpringCloud升级之路2020.0.x版-27.OpenFeign的生命周期-创建代理

    本系列代码地址:https://github.com/JoJoTec/spring-cloud-parent 接下来,我们开始分析 OpenFeign 的生命周期,结合 OpenFeign 本身的源代 ...

  9. SpringCloud升级之路2020.0.x版-28.OpenFeign的生命周期-进行调用

    本系列代码地址:https://github.com/JoJoTec/spring-cloud-parent 接下来,我们开始分析 OpenFeign 同步环境下的生命周期的第二部分,使用 Synch ...

随机推荐

  1. Kibana笔记

    • 根据id查询 GET index_1/doc/1 • 全文检索 GET index_1/doc/_search GET index_1/doc/_search{ "query" ...

  2. 【Android - 控件】之MD - FloatingActionButton的使用

    FloatingActionButton(FAB) 是 Android 5.0 新特性——Material Design 中的一个控件,是一种悬浮的按钮. FloatingActionButton 是 ...

  3. xmake从入门到精通8:切换编译模式

    xmake是一个基于Lua的轻量级现代化c/c++的项目构建工具,主要特点是:语法简单易上手,提供更加可读的项目维护,实现跨平台行为一致的构建体验. 本文我们会详细介绍下如何在项目构建过程中切换deb ...

  4. Oracle procedure 在命令行里面执行出错

    One procedure do well in SQL developer but error during exceute it under sqlplus command line: Remem ...

  5. Scrapy 框架 (学习笔记-1)

    环境: 1.windows 10 2.Python 3.7 3.Scrapy 1.7.3 4.mysql 5.5.53 一.Scrapy 安装 1. Scrapy:是一套基于Twisted的一部处理框 ...

  6. 在文件夹下所有文件中查找字符串(linux/windows)

    在linux下可以用 grep "String" filename.txt#字符串 文件名grep -r "String" /home/#递归查找目录下所有文件 ...

  7. openlayers4 入门开发系列之前端动态渲染克里金插值 kriging 篇(附源码下载)

    前言 openlayers4 官网的 api 文档介绍地址 openlayers4 api,里面详细的介绍 openlayers4 各个类的介绍,还有就是在线例子:openlayers4 官网在线例子 ...

  8. 2017 CCPC秦皇岛 H题 Prime set

    Given an array of  integers , we say a set  is a prime set of the given array, if  and  is prime. Ba ...

  9. (全国多校重现赛一)F-Senior Pan

    Senior Pan fails in his discrete math exam again. So he asks Master ZKC to give him graph theory pro ...

  10. 笔记||Python3之再识函数

    变量的作用域: 全局变量   -----  可以在函数内部被引用 局部变量   -----  函数内部 -- 只能在函数里面使用,在函数外部不能使用 在函数内部修改全局变量:global   x 缺省 ...