vue 网页文字中带#的话题颜色高亮

网页中显示文字时,带#开始和结束的文字蓝色高亮,就像微博话题一样
效果如下

html

<span v-html="parseComments('#吃货节#有什么好吃的')"></span> // 方法里面可以是变量,这里只是个演示

js

parseComments (value) {
     var exp
     exp = /(#|#)((?!#).)*(#|#)/g
     value = value.replace(/<[^>]*?>(.*?)/gi, '').replace(/(.*?)</[^>]*?>/gi, '').replace(exp, (item) => {
       let newVal = '<span class="text-blue">' + item + '</span>'
       return newVal
    })
     return value
  }


原文地址:https://www.cnblogs.com/lalalagq/p/9898444.html