vue2過濾器模糊查詢方法
更新時(shí)間:2018年09月16日 13:51:58 作者:seFei_Q
今天小編就為大家分享一篇vue2過濾器模糊查詢方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
如下所示:
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <body> <div id="app"> <input type="text" v-model='search' /> <ul v-for="item in searchData "> <li>{{item.name}},價(jià)格:¥{{item.price}}</li> </ul> </div> <script src="vue.js"></script> <script> var vm = new Vue({ el: '#app', data: { search: '', products: [{ name: '蘋果', price: 25, category: "水果" }, { name: '香蕉', price: 15, category: "水果" }, { name: '雪梨', price: 65, category: "水果" }, { name: '寶馬', price: 2500, category: "汽車" }, { name: '奔馳', price: 10025, category: "汽車" }, { name: '柑橘', price: 15, category: "水果" }, { name: '奧迪', price: 25, category: "汽車" }, { name: '火龍果', price: 25, category: "工具" }] }, computed: { searchData: function() { var search = this.search; var searchVal = '';//搜索后的數(shù)據(jù) if (search) { searchVal = this.products.filter(function(product) { return Object.keys(product).some(function(key) { //搜索所有的內(nèi)容 return String(product[key]).toLowerCase().indexOf(search) > -1; //只搜索問題內(nèi)容(某一個(gè)key) return String(product['questions']).toLowerCase().indexOf(search)>-1; }) }) return searchVal; } } } }) </script> </body> </html>
以上這篇vue2過濾器模糊查詢方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
關(guān)于vue3 vuex4 store的響應(yīng)式取值問題解決
這篇文章主要介紹了vue3 vuex4 store的響應(yīng)式取值問題,在實(shí)際生活中遇到這樣一個(gè)問題:在頁面中點(diǎn)擊按鈕,數(shù)量增加,值是存在store中的,點(diǎn)擊事件值沒變,如何解決這個(gè)問題,本文給大家分享解決方法,需要的朋友可以參考下2022-08-08Vue Transition實(shí)現(xiàn)類原生組件跳轉(zhuǎn)過渡動(dòng)畫的示例
本篇文章主要介紹了Vue Transition實(shí)現(xiàn)類原生組件跳轉(zhuǎn)過渡動(dòng)畫的示例,具有一定的參考價(jià)值,有興趣的可以了解一下2017-08-08Vue Router的手寫實(shí)現(xiàn)方法實(shí)現(xiàn)
這篇文章主要介紹了Vue Router的手寫實(shí)現(xiàn)方法實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03