【富文本、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 传给富文本插件 就可以了。

 

posted @ 2019-11-01 14:42  X1aoYE  阅读(570)  评论(0编辑  收藏  举报