一段后台配置的html字段,填充到页面的dom结构。
html里面有个id,要点击事件。这样写没效果,我要怎么改
export default class Rule extends React.Component {
constructor(props) {
super(props);
}
componentDidMount(){
const copyContentEle = document.getElementById('copy-content');
if(!utils.isNull(copyContentEle)){
const copyContent = copyContentEle.textContent;
copyContentEle.click(function(){
console.log(copyContent);
});
}
}
render() {
const index = this.props.index;
return (
<div className="rule">
{
this.props.data[`rule_text_${index}`] &&
<div>
<Title index={index} title={this.props.data[`rule_title_${index}`]}/>
<div dangerouslySetInnerHTML={{__html: this.props.data[`rule_text_${index}`]}}></div>
</div>
}
</div>
);
}
}
以上代码会报错
改了另外一种写法