使用计算属性app.js
var app5 = new Vue({
el: '#app5',
data: {
shoppingList: [
"Milk", "Donuts", "Cookies", "Chocolate", "Peanut Butter", "Pepto Bismol", "Pepto Bismol (Chocolate flavor)", "Pepto Bismol (Cookie flavor)"
],
key: ""
},
computed: {
filterShoppingList: function () {
// `this` points to the vm instance
var key = this.key;
var shoppingList = this.shoppingList;
return shoppingList.filter(function (item) {
return item.toLowerCase().indexOf(key.toLowerCase()) != -1
});;
}
}
})
app.html
<div id="app5">
<h2>Vue-for</h2>
<ul>
<li v-for="item in shoppingList">
{{ item }}
</li>
</ul>
<h2>Vue-for filter实现</h2>
<ul>
Filter Key<input type="text" v-model="key">
<li v-for="item in filterShoppingList">
{{ item }}
</li>
</ul>
</div>
最终效果实现了根据关键字来过滤列表的功能。
以上这篇Vue2.0 v-for filter列表过滤功能的实现就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
继续阅读与本文标签相同的文章
上一篇 :
Facebook放松了对一些加密货币广告的禁令
下一篇 :
TensorFlow实现iris数据集线性回归
-
Cassandra sstableloader工具使用及原理解析
2026-05-18栏目: 教程
-
Qt编写控件属性设计器1-加载插件
2026-05-18栏目: 教程
-
Qt编写控件属性设计器2-拖曳控件
2026-05-18栏目: 教程
-
Aliyun Serverless VSCode Extension v1.9.0 发布
2026-05-18栏目: 教程
-
【从入门到放弃-ZooKeeper】ZooKeeper实战-分布式队列
2026-05-18栏目: 教程
