【富文本、JS】将接口传来的全部纯URL替换为富文本插件能识别到的img标签
replaceURLWithImage (text) { var a = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; this.html = text.replace(a,"<img src='$1'></img>"); console.log(this.html) }
text就是你要穿的URL,例如:
this.html 传给富文本插件 就可以了。