码迷,mamicode.com
首页 > 其他好文 > 详细

vue的filter用法,检索内容

时间:2018-02-09 20:49:00      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:mod   express   filters   gpo   model   ase   key   put   .sh   

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; //在使用filter时需要注意的是,前面调用的是需要使用filter的数组,而给filter函数传入的是数组中的每个item,也就是说filter里面的函数,是每个item要去做的,并将每个结果返回。
return shoppingList.filter(function (item) {
return item.toLowerCase().indexOf(key.toLowerCase()) != -1 });;
}
}
})

<ul> Filter Key<input type="text" v-model="key"> <li v-for="item in filterShoppingList"> {{ item }} </li> </ul>

  

vue的filter用法,检索内容

标签:mod   express   filters   gpo   model   ase   key   put   .sh   

原文地址:https://www.cnblogs.com/holy-amy/p/8436502.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!