Auto commit

上级 783c43dc
...@@ -4,19 +4,14 @@ ...@@ -4,19 +4,14 @@
<!-- <div v-html="brightenKeyword(list, text)"></div> --> <!-- <div v-html="brightenKeyword(list, text)"></div> -->
--------------------------------------------------------------- ---------------------------------------------------------------
<br /> <br />
<input <div>
type="text" 切换显示文本:
@keyup.enter="getMachlist" <button @click="isshow = true">原文本</button>
v-model="wordage" <button @click="isshow = false">匹配文本</button>
placeholder="请输入关键字" </div>
/> <input type="text" @keyup.enter="getMachlist" v-model="wordage" placeholder="请输入关键字" />
<input type="button" @click="getMachlist" value="确定" /> <input type="button" @click="getMachlist" value="确定" />
<div <div style="" v-for="item in machlist" :key="item.id" v-html="item.title"></div>
style=""
v-for="item in machlist"
:key="item.id"
v-html="item.title"
></div>
</div> </div>
</template> </template>
...@@ -55,6 +50,7 @@ export default { ...@@ -55,6 +50,7 @@ export default {
], //全部列表 ], //全部列表
machlist: [], // 匹配列表 machlist: [], // 匹配列表
wordage: "", //搜索框输入的值 wordage: "", //搜索框输入的值
isshow: true//是否显示原文本
}; };
}, },
mounted() { mounted() {
...@@ -68,6 +64,9 @@ export default { ...@@ -68,6 +64,9 @@ export default {
this.getMachlist(); this.getMachlist();
} }
}, },
isshow(){
this.getMachlist();
}
}, },
methods: { methods: {
// 模糊查询 高亮匹配 // 模糊查询 高亮匹配
...@@ -92,17 +91,31 @@ export default { ...@@ -92,17 +91,31 @@ export default {
// 声明正则校验 (正则表达式,"匹配模式") /gi(全文查找、忽略大小写) // 声明正则校验 (正则表达式,"匹配模式") /gi(全文查找、忽略大小写)
const reg = new RegExp(value, "gi"); const reg = new RegExp(value, "gi");
// 循环遍历 this.list 使用数据进行渲染 resultList 使用只符合条件的数据 // 循环遍历 this.list 使用数据进行渲染 resultList 使用只符合条件的数据
this.list.forEach((item) => { if (this.isshow) {
let obj = { this.list.forEach((item) => {
id: item.id, let obj = {
title: item.title.replace( id: item.id,
reg, title: item.title.replace(
//筛选出来的文字加样式 reg,
(val) => `<span style='color:red'>${val}</span>` //筛选出来的文字加样式
), (val) => `<span style='color:red'>${val}</span>`
}; ),
dataList.push(obj); };
}); dataList.push(obj);
});
} else {
resultList.forEach((item) => {
let obj = {
id: item.id,
title: item.title.replace(
reg,
//筛选出来的文字加样式
(val) => `<span style='color:red'>${val}</span>`
),
};
dataList.push(obj);
});
}
// 赋值 // 赋值
this.machlist = dataList; this.machlist = dataList;
}, },
...@@ -111,9 +124,9 @@ export default { ...@@ -111,9 +124,9 @@ export default {
</script> </script>
<style scoped> <style scoped>
.home{ .home {
width: 100%; width: 100%;
text-align: center; text-align: center;
margin: 0 auto; margin: 0 auto;
} }
</style> </style>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册