Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

这是一道题

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>

<body>
<div id="app" style="display: none"></div>
<!--//react怎么通过组件修改这个div的样式,比如修改他的display,不能操作dom-->
</body>
</html>

clipboard.png
下面是js

import React from 'react'
import {render} from 'react-dom'
class Application extends React.Component {
    render(){
        return (
            this.props.children
        )
    }
}
//下面不能修改
render(<Application><a>123</a></Application>, document.getElementById('app'));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
435 views
Welcome To Ask or Share your Answers For Others

1 Answer

componentDidMount钩子中就可以使用普通的dom方法获得根元素啊,那时候不想怎么操作就怎么操作


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...