// str是整段文字,keyWord是需高亮文字
highlightText (str, keyWord) {
const key = '(' + keyWord.replace(/([\+\.\*\|\?\-\(\[\^\$])/g, '\\$1').replace(/\s+/g, '|') + ')'
const pattern = new RegExp(key, 'g')
const str2 = str.replace(pattern, `<span style="color: #f00;">${keyWord}</span>`)
return str2
},
vue关键字高亮有正则关键字报错
最新推荐文章于 2024-05-09 17:38:33 发布