vue實(shí)現(xiàn)實(shí)時(shí)搜索顯示功能
本文實(shí)例為大家分享了vue實(shí)現(xiàn)實(shí)時(shí)搜索顯示的具體代碼,供大家參考,具體內(nèi)容如下
<template> //綁定搜索的關(guān)鍵字 <input type="text" class="form-control" placeholder="搜索" v-model="filterInput"/> ?<table ?class="table table-striped"> ? ? ? <thead> ? ? ? ? <tr> ? ? ? ? ? <th>姓名</th> ? ? ? ? ? <th>電話</th> ? ? ? ? ? <th>郵箱</th> ? ? ? ? ? <th></th> ? ? ? ? </tr> ? ? ? </thead> ? ? ? <tbody> ? ? ? ? <!-- 遍歷搜索的東西,觸發(fā)filterBy方法遍歷的時(shí)候和搜索框內(nèi)容進(jìn)行匹配 例如name--> ? ? ? ? <!-- 如果不搜索,遍歷的就是所有數(shù)據(jù) --> ? ? ? ? <tr v-for="(item,index) in filterBy(customer,filterInput)" :key="index"> ? ? ? ? ? <td>{{item.name}}</td> ? ? ? ? ? <td>{{item.phone}}</td> ? ? ? ? ? <td>{{item.email}}</td> ? ? ? ? ? <!-- 通過對應(yīng)的id查看詳情 ?拼接id--> ? ? ? ? ? <!-- 在details中通過攜帶id發(fā)送后臺請求數(shù)據(jù):to是因?yàn)閠o現(xiàn)在的值是變量要綁定,如果是單純的字符串就不需要綁定--> ? ? ? ? ? <td> ? ? ? ? ? ? <!-- <router-link class="btn btn-default" :to="'/customer/'+item[index]._id" style="backgroundcolor:blue ">查看詳情</router-link> --> ? ? ? ? ? ? <!-- <router-link class="btn btn-default" :to="'/customer/'+item._id" style="backgroundcolor:blue " >查看詳情</router-link> --> ? ? ? ? ? ? <div class="btn btn-default" style="backgroundcolor:blue" @click="handleclick(item)">查看詳情</div> ? ? ? ? ? </td> ? ? ? ? </tr> ? ? ? </tbody> ? ? </table> ? ?? </template> <script> export default { ? name: "customers", ? data() { ? ? return { ? ? ? customer: [], ? ? ? filterInput:"", ? ? ? childrenmag:'' ? ? }; ? }, ? ? methods: { ? ? // 異步請求數(shù)據(jù) ? ? async fetchCustomers() { ? ? ? const res = await this.$http.get("/users"); ? ? ? this.customer = res.data; ? ? }, ? ? filterBy(customers, inputvalue) { ? ? ? // filter方法遍歷整個數(shù)組 ? ? ? return customers.filter(customer => { ? ? ? ? // 注意match不能遍里數(shù)字,true,false ? ? ? ? return customer.name.match(inputvalue); ? ? ? }); ? ? } ? ? } </script>
filterBy方法查找對應(yīng)關(guān)鍵字的那條數(shù)據(jù)。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
element-ui中el-cascader動態(tài)加載和默認(rèn)值詳解
vue+elementUI項(xiàng)目中el-cascader級聯(lián)選擇器使用頻率非常高,下面這篇文章主要給大家介紹了關(guān)于element-ui中el-cascader動態(tài)加載和默認(rèn)值的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-05-05vue3.0父子傳參,子修改父數(shù)據(jù)的實(shí)現(xiàn)
這篇文章主要介紹了vue3.0父子傳參,子修改父數(shù)據(jù)的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-04-04vue2.0中g(shù)oods選購欄滾動算法的實(shí)現(xiàn)代碼
這篇文章主要介紹了vue2.0中g(shù)oods選購欄滾動算法的實(shí)現(xiàn)代碼,需要的朋友可以參考下2017-05-05教你如何開發(fā)Vite3插件構(gòu)建Electron開發(fā)環(huán)境
這篇文章主要介紹了如何開發(fā)Vite3插件構(gòu)建Electron開發(fā)環(huán)境,文中給大家提到了如何讓 Vite 加載 Electron 的內(nèi)置模塊和 Node.js 的內(nèi)置模塊,需要的朋友可以參考下2022-11-11vue2.0的contextmenu右鍵彈出菜單的實(shí)例代碼
本篇文章主要介紹了vue2.0的contextmenu右鍵彈出菜單的實(shí)例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-07-07