hightLight.js
366 Bytes
export default {
methods: {
hightLight (keyWord, suggtion) {
// 使用 regexp 构造函数,因为这里要匹配的是一个变量
const reg = new RegExp(keyWord, 'ig')
const newSrt = String(suggtion).replace(reg, function (p) {
return '<font style="color:#409eff">' + p + '</font>'
})
return newSrt
}
}
}