vue實現(xiàn)實時搜索顯示功能
更新時間:2022年04月18日 11:24:55 作者:Amnesia?
這篇文章主要為大家詳細介紹了vue實現(xiàn)實時搜索顯示功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了vue實現(xiàn)實時搜索顯示的具體代碼,供大家參考,具體內(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方法遍歷的時候和搜索框內(nèi)容進行匹配 例如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是因為to現(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)文章
el-tree的實現(xiàn)葉子節(jié)點單選的示例代碼
本文主要介紹了el-tree的實現(xiàn)葉子節(jié)點單選的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08
vue 如何從單頁應(yīng)用改造成多頁應(yīng)用
這篇文章主要介紹了vue 如何從單頁應(yīng)用改造成多頁應(yīng)用,幫助大家更好的理解和使用vue,感興趣的朋友可以了解下2020-10-10
vue?實現(xiàn)列表跳轉(zhuǎn)至詳情且能添加至購物車功能
列表頁面顯示數(shù)據(jù),點擊跳轉(zhuǎn)到對應(yīng)的詳情頁,詳情頁可以添加并跳轉(zhuǎn)到購物車,購物車具有常見功能,這篇文章主要介紹了vue?實現(xiàn)列表跳轉(zhuǎn)至詳情且能添加至購物車,需要的朋友可以參考下2022-10-10
詳解Vue單元測試Karma+Mocha學(xué)習(xí)筆記
本篇文章主要介紹了詳解Vue單元測試Karma+Mocha學(xué)習(xí)筆記,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-01-01
vue 2.8.2版本配置剛進入時候的默認(rèn)頁面方法
今天小編就為大家分享一篇vue 2.8.2版本配置剛進入時候的默認(rèn)頁面方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09

