使用场景,后台返回数据需要进行标签替换或者其它处理,生成新的标签属性,无法将 RestAPI 数据进行展示:
import React, {Component, PropTypes} from 'react';
import * as formatContent from 'util/formatWbsContent.js';
const getWbContent = (content) => {
return <div dangerouslySetInnerHTML={formatContent.createMarkup(content)}/>;
}
class ShowContent extends Component {
constructor(props){
super()
}
render(){
return(
{getWbContent(this.props.content)}
)
}
}
//'util/formatWbsContent.js'
export function createMarkup(text) {
return {__html: getWbContent(text)};
}
export const getWbContent = (content) => {
/*
*
*一些标签替换等操作
*
*/
return contentHTML;
}