关于搜索内容高亮问题

93 阅读1分钟
 watch: {
    搜索的高亮文字
    ishtmltext:{
      handler(n,o){
        if(!this.ishtml){
         this.defaultcont(n,this.cont)
        }
        },
      deep:true,
      immediate: true,
    },
   
  },
  
    defaultcont(kw, str) {
      const reg = new RegExp(kw, 'ig') // ig 是所有的意思 而非在发现第一个匹配项时立即停止
      this.conthtml = str.replace(
        reg,
        (match) => `<span style="color: #00BEBD">${match}</span>`
      );
    }