Vue2.0 v-for filter列表過濾功能的實(shí)現(xiàn)
更新時間:2018年09月07日 14:46:52 作者:大灰狼的小綿羊哥哥
今天小編就為大家分享一篇Vue2.0 v-for filter列表過濾功能的實(shí)現(xiàn),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
使用計(jì)算屬性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實(shí)現(xiàn)</h2>
<ul>
Filter Key<input type="text" v-model="key">
<li v-for="item in filterShoppingList">
{{ item }}
</li>
</ul>
</div>
最終效果實(shí)現(xiàn)了根據(jù)關(guān)鍵字來過濾列表的功能。
以上這篇Vue2.0 v-for filter列表過濾功能的實(shí)現(xiàn)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue.js異步上傳文件前后端實(shí)現(xiàn)代碼
這篇文章主要為大家詳細(xì)介紹了vue.js異步上傳文件前后端的實(shí)現(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-08-08
vue3中使用VueParticles實(shí)現(xiàn)粒子動態(tài)背景效果
為了提高頁面展示效果,特別類似于登錄界面內(nèi)容比較單一的,粒子效果作為背景經(jīng)常使用到,vue工程中利用vue-particles可以很簡單的實(shí)現(xiàn)頁面的粒子背景效果,本文給大家分享vue粒子動態(tài)背景效果實(shí)現(xiàn)代碼,需要的朋友參考下吧2022-05-05
vue+layui實(shí)現(xiàn)select動態(tài)加載后臺數(shù)據(jù)的例子
今天小編就為大家分享一篇vue+layui實(shí)現(xiàn)select動態(tài)加載后臺數(shù)據(jù)的例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-09-09

