zoukankan      html  css  js  c++  java
  • Vue与React的异同 -生命周期

    vue的生命周期

    创建前 beforeCreate

    创建   create

    挂载前 beforeMount

    挂载 mounted

    更新前 beforeUpdate

    更新 updated

    销毁前 beforeDestroyed

    销毁  destoryed

     methods --方法

    Vue 实例生命周期

    -----------------------------------华丽的分割线-------------------------

    一个React组件的生命周期分为三个部分:挂载期(Mounting)、存在更新期(Updating)和销毁时(Unmounting)。

    import React,{ Component } from 'react';

    class Demo extends Component {
    constructor(props,context) {
    super(props,context)
    this.state = {
    //定义state
    }
    }
    componentWillMount () { //组件将要挂载
    }
    componentDidMount () { //组件渲染完成 这里调用ajax请求,返回数据setstate组件会重新渲染
    }
    componentWillReceiveProps (nextProps) {
    }
    shouldComponentUpdate (nextProps,nextState) {
    }
    componentWillUpdate (nextProps,nextState) {
    }
    componentDidUpdate (prevProps,prevState) {
    }
    render () {
    return (
    <div></div>
    )
    }
    componentWillUnmount () {
    }
    }
    export default Demo;
    componentDidMount方法中放ajax请求--服务器会根据变量渲染,Constructor中设置变量初始化


    如果你觉得我的文章对您有帮助,给点鼓励,谢谢

  • 相关阅读:
    Nmap笔记
    Spring AOP(一)
    Spring IOC(三)
    Spring IOC(二)
    Spring IOC(一)
    bootstrap 使用(三)
    bootstrap 使用(二)
    bootstrap 使用(一)
    js(二)
    QQ邮件
  • 原文地址:https://www.cnblogs.com/aqbyygyyga/p/9922281.html
Copyright © 2011-2022 走看看