vue2过滤器模糊查询方法
作者:seFei_Q 时间:2024-04-28 09:21:03
如下所示:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div id="app">
<input type="text" v-model='search' />
<ul v-for="item in searchData ">
<li>{{item.name}},价格:¥{{item.price}}</li>
</ul>
</div>
<script src="vue.js"></script>
<script>
var vm = new Vue({
el: '#app',
data: {
search: '',
products: [{
name: '苹果',
price: 25,
category: "水果"
}, {
name: '香蕉',
price: 15,
category: "水果"
}, {
name: '雪梨',
price: 65,
category: "水果"
}, {
name: '宝马',
price: 2500,
category: "汽车"
}, {
name: '奔驰',
price: 10025,
category: "汽车"
}, {
name: '柑橘',
price: 15,
category: "水果"
}, {
name: '奥迪',
price: 25,
category: "汽车"
}, {
name: '火龙果',
price: 25,
category: "工具"
}]
},
computed: {
searchData: function() {
var search = this.search;
var searchVal = '';//搜索后的数据
if (search) {
searchVal = this.products.filter(function(product) {
return Object.keys(product).some(function(key) {
//搜索所有的内容
return String(product[key]).toLowerCase().indexOf(search) > -1;
//只搜索问题内容(某一个key)
return String(product['questions']).toLowerCase().indexOf(search)>-1;
})
})
return searchVal;
}
}
}
})
</script>
</body>
</html>
来源:https://blog.csdn.net/seFei_Q/article/details/78788102
标签:vue2,过滤器,查询
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
避免重复写代码的小函数
2008-09-21 13:41:00
![](https://img.aspxhome.com/file/UploadPic/20089/21/2008921134758493s.gif)
使用PyCharm安装pytest及requests的问题
2023-01-17 13:10:46
![](https://img.aspxhome.com/file/2023/4/117984_0s.png)
浅析python参数的知识点
2022-12-16 01:39:32
![](https://img.aspxhome.com/file/2023/2/133292_0s.png)
举例讲解Python常用模块
2022-03-21 07:35:49
pycharm 使用心得(三)Hello world!
2022-10-08 09:59:56
![](https://img.aspxhome.com/file/2023/6/130606_0s.jpg)
python利用socketserver实现并发套接字功能
2021-01-28 16:36:45
![](https://img.aspxhome.com/file/2023/1/72011_0s.jpg)
JavaScript控制台的更多功能
2024-02-24 12:46:42
python算法与数据结构之单链表的实现代码
2022-09-30 14:35:39
![](https://img.aspxhome.com/file/2023/0/98820_0s.png)
python 梯度法求解函数极值的实例
2023-08-11 07:33:05
详解Numpy中的广播原则/机制
2023-11-15 02:49:44
地图网站的需求功能与体验
2009-03-01 11:15:00
![](https://img.aspxhome.com/file/UploadPic/20093/1/01_b-87s.jpg)
win10系统配置GPU版本Pytorch的详细教程
2023-07-21 19:30:38
![](https://img.aspxhome.com/file/2023/1/78541_0s.png)
用Oracle并行查询发挥多CPU的威力
2010-07-23 12:52:00
js点击事件的执行过程实例分析【冒泡与捕获】
2024-02-27 07:53:34
Python 获取当前路径3种方法
2023-04-15 00:03:24
![](https://img.aspxhome.com/file/2023/7/127667_0s.png)
SQL Server错误代码大全及解释(留着备用)
2012-07-11 16:17:03
Golang中Set类型的实现方法示例详解
2024-02-13 23:45:11
python 删除excel表格重复行,数据预处理操作
2023-04-19 06:10:33
Python 继承,重写,super()调用父类方法操作示例
2022-08-09 13:22:13
![](https://img.aspxhome.com/file/2023/4/115064_0s.png)
python中的decorator的作用详解
2021-05-24 16:44:40