pageContent包含一个table,其中有后台传来的关键词参数,需要高亮显示,我该如何操作?
<body v-html="pageContent"> </body>
export default {
data() {
return {
pageContent: ''
}
},
created() {
this.getData();
},
methods: {
getData() {
const formData = this.$route.params;
let htmlContent = formData.content;
let str = htmlContent.split('body')[1];
this.pageContent = str.slice(str.indexOf('>') + 1, -2);
},
}
}
正则替换下下就行了
var re=new RegExp('(关键字)','gi')//注意改这里
this.pageContent = str.slice(str.indexOf('>') + 1, -2).replace(re,'<font color=red>$1</font>')
正则 找到关键词 ,替换成 标签