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>
? ? ? ? ? <!-- 通過(guò)對(duì)應(yīng)的id查看詳情 ?拼接id-->
? ? ? ? ? <!-- 在details中通過(guò)攜帶id發(fā)送后臺(tái)請(qǐng)求數(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: {
? ? // 異步請(qǐng)求數(shù)據(jù)
? ? async fetchCustomers() {
? ? ? const res = await this.$http.get("/users");
? ? ? this.customer = res.data;
? ? },
? ? filterBy(customers, inputvalue) {
? ? ? // filter方法遍歷整個(gè)數(shù)組
? ? ? return customers.filter(customer => {
? ? ? ? // 注意match不能遍里數(shù)字,true,false
? ? ? ? return customer.name.match(inputvalue);
? ? ? });
? ? }
? ? }
</script>filterBy方法查找對(duì)應(yīng)關(guān)鍵字的那條數(shù)據(jù)。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
el-tree的實(shí)現(xiàn)葉子節(jié)點(diǎn)單選的示例代碼
本文主要介紹了el-tree的實(shí)現(xiàn)葉子節(jié)點(diǎn)單選的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08
vue中Echarts圖表寬度沒(méi)占滿的問(wèn)題
這篇文章主要介紹了vue中Echarts圖表寬度沒(méi)占滿的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10
vue 如何從單頁(yè)應(yīng)用改造成多頁(yè)應(yīng)用
這篇文章主要介紹了vue 如何從單頁(yè)應(yīng)用改造成多頁(yè)應(yīng)用,幫助大家更好的理解和使用vue,感興趣的朋友可以了解下2020-10-10
vue keep-alive的簡(jiǎn)單總結(jié)
這篇文章主要介紹了vue中的keep-alive的相關(guān)資料,幫助大家更好的理解和使用vue框架,感興趣的朋友可以了解下2021-01-01
vue?實(shí)現(xiàn)列表跳轉(zhuǎn)至詳情且能添加至購(gòu)物車(chē)功能
列表頁(yè)面顯示數(shù)據(jù),點(diǎn)擊跳轉(zhuǎn)到對(duì)應(yīng)的詳情頁(yè),詳情頁(yè)可以添加并跳轉(zhuǎn)到購(gòu)物車(chē),購(gòu)物車(chē)具有常見(jiàn)功能,這篇文章主要介紹了vue?實(shí)現(xiàn)列表跳轉(zhuǎn)至詳情且能添加至購(gòu)物車(chē),需要的朋友可以參考下2022-10-10
詳解Vue單元測(cè)試Karma+Mocha學(xué)習(xí)筆記
本篇文章主要介紹了詳解Vue單元測(cè)試Karma+Mocha學(xué)習(xí)筆記,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-01-01
在uni-app中使用element-ui的方法與報(bào)錯(cuò)解決
我們?cè)陂_(kāi)web開(kāi)發(fā)的時(shí)候,經(jīng)常會(huì)使用到element或者uview-ui,下面這篇文章主要給大家介紹了關(guān)于在uni-app中使用element-ui的方法與報(bào)錯(cuò)解決的相關(guān)資料,需要的朋友可以參考下2022-04-04
vue 2.8.2版本配置剛進(jìn)入時(shí)候的默認(rèn)頁(yè)面方法
今天小編就為大家分享一篇vue 2.8.2版本配置剛進(jìn)入時(shí)候的默認(rèn)頁(yè)面方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-09-09

