uni-app 微信小程序 搜索替换关键字且高亮显示

 <u-parse :content="highlightedContent(item.content)"></u-parse>
highlightedContent(content) {
      let str = ''
      if (!this.keyword) {
        str = content
        return str
      }

      const regExp = new RegExp(this.keyword, "gi");
      str = content.replace(regExp, (match) => {
        return `<text class="highlight">${match}</text>`;
      });
      return `<view class="md-flex">${str}</view>`
    },

 

posted @ 2025-06-27 17:27  小菜波  阅读(51)  评论(0)    收藏  举报