搜索文字高亮

 highlight(keyWords, resultsList) {
      if (keyWords && keyWords.length > 0) {
        // 匹配关键字正则
        let replaceReg = new RegExp(keyWords, 'g')
        // 高亮替换v-html值
        let replaceString = '<span style="color:#F74C31">' + keyWords + '</span>'
        resultsList = resultsList.replace(replaceReg, replaceString)
      }
      return resultsList
    }

  

posted @ 2021-09-17 15:03  仙乄  阅读(13)  评论(0编辑  收藏  举报