WeChat applet rich text long press to copy and paste

If you want to copy by long pressing in the applet, you have to use the text component, but text cannot convert rich text content. To convert rich text content, you have to use the rich-text component, but rich-text does not support copying

我也是苦恼了好久,就用了一个蠢办法,把后台传的富文本用正则转成了普通文本,然后再用text组件,实在没办法了,具体代码如下

First write a converted js method

getSimpleText(html) {
	var re1 = /<(\/)?[^>].*?>/g; 
	var msg = html.replace(re1, ''); 
	msg = msg.replace(/&nbsp;/ig, "");
	return msg;
}

Just call

const newHtml =  getSimpleText(富文本地址)

Then our text component

<text user-select="true">
	{
   
   {newHtml}}
</text>

If there are any other good solutions, please teach me... I feel too...

Guess you like

Origin blog.csdn.net/weixin_45389051/article/details/114294495