js:
export const highlightKeyword = (str, key) => { if (!str) return ''; let reg = new RegExp('(' + key + ')', 'gi'); let newstr = str.replace(reg, '<em class="heightlight-kd">$1</em>'); return newstr; };
css:
.heightlight-kd {
color: blue;
}
html:
import { highlightKeyword } from 'common'; renderHighlightKeyword = field => { return <span dangerouslySetInnerHTML={{ __html: highlightKeyword(field, props.keyword) }}></span>; }; this.columns = [ { title: '类型', dataIndex: 'name', key: 'name', render: this.renderHighlightKeyword, }]