关键字替换-javascript

const msgContent = str.replace(/{{([^}]+)}}/g, function(full, part) { console.log(full, part); return `<span class='color'>${part}</span>`; });

上述代码可用于,如:

const str = '{{guoba}}释放了客户'

输出:

 可用于关键字替换成html标签,然后可以用 react 的 dangerouslySetInnerHTML

<div className="txt-content" dangerouslySetInnerHTML={{ __html: decodeURIComponent(msgContent)}} />
原文地址:https://www.cnblogs.com/yxfboke/p/14350597.html