【发布时间】:2019-01-06 01:53:10
【问题描述】:
我想在安装组件时动态添加一些 div 元素。我尝试了以下代码
<div className="resumebuilder__structure" ref="panel_holder">
</div>
我在生命周期钩子中调用的函数
getPanels = () => {
return this.props
.resumeTemplate
.roughTemplateStructure
.roughScale.map((roughS) => {
const uid = uuid();
this.updatePanelInTemplate(uid);
const elem = <div ref={uid} className={roughS.class} ></div>;
return elem;
});
}
生命周期方法
componentDidMount() {
this.refs.panel_holder.appendChild(this.getPanels());
}
但我收到以下错误
Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
有人知道吗?
---- 更新--
虽然我继续使用其他方法,但仍然没有找到答案。有知道的请留言。
【问题讨论】:
标签: javascript reactjs