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

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
  }


相关文章:

  • 2021-12-12
  • 2021-09-24
  • 2021-08-06
  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-04
  • 2021-07-20
  • 2022-12-23
  • 2021-12-13
  • 2022-12-23
  • 2021-12-21
相关资源
相似解决方案