Vue里面搜索标红

1.首先再methods里面写一个方法

signKeyword (val) {

let keyword = this.title  //搜索的值

if (val.indexOf(keyword) !== -1) {
return val.replace(keyword, `<font color='#f00'>${keyword}</font>`)
} else {
return val
}
},

2.在后台请求的数据找个东西接一下,我这里用的records使用1中的方法标红,然后给data渲染到页面

const records=searchArray.dataSet.records//后台的数据
records.map((item)=>{
   item.title = this.signKeyword(item.title)
})
this.searchArray = records//页面渲染的数据

posted @ 2020-10-09 17:39  做个人把  阅读(625)  评论(0)    收藏  举报