console
new Vue({
el: "#app",
data: {
search: "",
list: [
{ id: 1, text: "百度,一下就知道" },
{ id: 2, text: "天猫,天上的猫" },
{ id: 3, text: "京东,受惊的刘强东" },
{ id: 4, text: "阿里巴巴,阿里的爸爸" }
]
},
methods: {
replaceT(text , search) {
return text.replace(search, `<span style="color: red">${search}</span>`);
}
}
})
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<div id="app">
<input type="text" v-model="search" />
<ul>
<li v-for="item in list" :key="item.id" v-html="replaceT(item.text, search)"></li>
</ul>
</div>
</body>
</html>