React/anu实现弹出层2

栏目: 服务器 · 发布时间: 8年前

内容简介:React/anu实现弹出层2

这次是使用了一个比较罕见的APIReactDOM.unstable_renderSubtreeIntoContainer,ReactDOM.unstable_renderSubtreeIntoContainer与ReactDOM.render 的区别是,一个能传parentContext,一个不能。

function  RealModal (props){
   return <div className='modal'>{props.children}</div>
}
  class Modal extends React.Component {
    appendMaskIntoDoc() {
        console.log(this)
        ReactDOM.unstable_renderSubtreeIntoContainer(
            this,
            <RealModal {...this.props}>
                {this.props.children}
            </RealModal>,
            this.container
        )
    }

    componentDidMount() {
      var div = this.container = document.createElement('div')
        div.innerHTML = '<p>1111</p><p>222</p>'
        div.className = 'placeholder'
        document.body.appendChild(div)
      
        this.appendMaskIntoDoc()
    }

    componentDidUpdate() {
        console.log('更新')
        this.appendMaskIntoDoc()
    }

    componentWillUnmount() {
        console.log('componentWillUnmount')
        document.body.removeChild(this.container)
    }

    render() {
        return null
    }
}
window.onload = function(){
    ReactDOM.render(<Modal title="aaa">99999</Modal>, document.getElementById('select'))

    setTimeout(function(){
       ReactDOM.render(<Modal title="aaa">新内容</Modal>, document.getElementById('select'))
    },500)
}

以上所述就是小编给大家介绍的《React/anu实现弹出层2》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

解决网页设计一定会遇到的210个问题

解决网页设计一定会遇到的210个问题

2006-4 / 42.00元

如何选择适合、简单、方便、快速的方法来解决您的网页设计问题?不会HTML、JavaScript、CSS也可轻易完成许多网页功能与特效。本书包含上百种HTML、JavaScript、CSS使用应用技巧与盲点解说,包含10个常用表单资料判断函数与特殊技巧,不必修改就可用于任何网页。本书现有的多数网页设计书籍相辅相成,让您事半功倍地完成工作。   许多计算机书籍都是从某个语言或者某个软件的......一起来看看 《解决网页设计一定会遇到的210个问题》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

html转js在线工具
html转js在线工具

html转js在线工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具