Vue2.0 v-for filter列表过滤功能的实现
时间:2021-04-27 09:07:01|栏目:vue|点击: 次
使用计算属性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>
最终效果实现了根据关键字来过滤列表的功能。
上一篇:VUE实现可随意拖动的弹窗组件
栏 目:vue
下一篇:vue打包相关细节整理(小结)
本文标题:Vue2.0 v-for filter列表过滤功能的实现
本文地址:http://www.codeinn.net/misctech/109477.html






