Vue2.0 v-for filter列表過濾功能的實現(xiàn)
更新時間:2018年09月07日 14:46:52 作者:大灰狼的小綿羊哥哥
今天小編就為大家分享一篇Vue2.0 v-for filter列表過濾功能的實現(xiàn),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
使用計算屬性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實現(xiàn)</h2> <ul> Filter Key<input type="text" v-model="key"> <li v-for="item in filterShoppingList"> {{ item }} </li> </ul> </div>
最終效果實現(xiàn)了根據(jù)關鍵字來過濾列表的功能。
以上這篇Vue2.0 v-for filter列表過濾功能的實現(xiàn)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
vue3 Element Plus中icon圖標不顯示的解決方案
這篇文章主要介紹了vue3 Element Plus中icon圖標不顯示的解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03vue中計算屬性(computed)、methods和watched之間的區(qū)別
這篇文章主要給大家介紹了關于vue中計算屬性(computed)、methods和watched之間區(qū)別的相關資料,文中通過示例代碼介紹的非常詳細,對大家具有一定的參考學習價值,需要的朋友們下面跟著小編來一起學習學習吧。2017-07-07vue中promise的使用及異步請求數(shù)據(jù)的方法
這篇文章主要介紹了vue中promise的使用及異步請求數(shù)據(jù)的方法,文章給大家較詳細的介紹了遇到的問題及解決方法,需要的朋友可以參考下2018-11-11