溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Vue怎么實現(xiàn)分頁與輸入框關(guān)鍵字篩選功能

發(fā)布時間:2021-05-20 14:33:26 來源:億速云 閱讀:300 作者:小新 欄目:web開發(fā)

這篇文章主要介紹Vue怎么實現(xiàn)分頁與輸入框關(guān)鍵字篩選功能,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

分頁的實現(xiàn)(Vue+Element)+輸入框關(guān)鍵字篩選

1.這里用的是Element 自帶的分頁組件

<template>
<div class="sales-table">
<div class="order-list-header">訂單列表</div>
<div class="back-box">
<div class="search-box"><input type="text" name="" id="" class="order-search-input" placeholder="關(guān)鍵詞" v-model='search'></div>
</div>
<div class="table-box">
<div class="table-list" v-for="(cash, index) in orderList.slice((currentPage-1)*pagesize,currentPage*pagesize)" :key="cash.id">
<table id="tableSort" >
<thead class="table-header">
<tr>
<th class="left-radius">序號</th>
<th>創(chuàng)建時間</th>
<th>訂單ID</th>
<th>所屬用戶姓名</th>
<th>所屬用戶ID</th>
<th>所屬用戶手機</th>
<th>所屬用戶層級</th>
<th>訂單金額</th>
<th>訂單狀態(tài)</th>
<th>審核狀態(tài)</th>
<th>收件人</th>
<th>聯(lián)系電話</th>
<th>收貨地址</th>
<th>訂單備注</th>
<th class="right-radius">操作</th>
</tr>
</thead>
<tbody class="table-lists">
<tr class="first-tr">
<td class="sequence">{{ index+1>9?index+1:"0"+(index+1) }}</td>
<td class="sequence">{{cash.createTime}}</td>
<td class="sequence">{{cash.orderId}}</td>
<td class="sequence">{{cash.cilentName}}</td>
<td class="sequence">{{cash.cilentId}}</td>
<td class="sequence">{{cash.cilentPhone}}</td>
<td class="sequence">{{cash.cilentGrade}}</td>
<td class="sequence money">¥{{cash.orderPrice}}</td>
<td class="sequence">{{cash.orderState}}</td>
<td class="sequence">{{cash.auditState}}</td>
<td class="sequence">{{cash.receiver}}</td>
<td class="sequence">{{cash.phone}}</td>
<td class="sequence">{{cash.address}}</td>
<td class="sequence">{{cash.orderRemark}}</td>
<td class="sequence"><a class="view-order">查看</a><a class="edit-order">編輯</a><a class="delete-order">刪除</a></td>
</tr>
</tbody>
</table>
</div>
</div>
<-- 分頁 -->
<div class="page">
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage"
:page-sizes="[5, 10, 20, 40]"
:page-size="pagesize"
layout="total, sizes, prev, pager, next, jumper"
:total="Cashdata.length">
</el-pagination>
</div>
</div>
</template>

2.文中標(biāo)紅的字不再是循環(huán)數(shù)組,名字隨意取,在后面搜索關(guān)鍵字部分也標(biāo)紅了。數(shù)據(jù)多分頁效果會更加明顯。

<script>
export default {
data() {
  return {
    currentPage:1, //初始頁
    pagesize:10,//每頁的數(shù)據(jù)// 搜索關(guān)鍵詞
    search:"",
    Cashdata: [{
      createTime:"2019/1/21/ 14:30:30",
      orderId: "1555555454",
      cilentName:"網(wǎng)三",
      cilentId:"21313216544",
      cilentPhone:"13976605432",
      cilentGrade:"1",
      orderPrice:"454664",
      orderState:"已提交",
      auditState: "系統(tǒng)已確認",
      receiver: "和大寶",
      phone:"16565644444",
      address:"廣東省深圳市*************************",
      orderRemark:"少放醋,多方唐撒旦啊阿薩大薩達"
    },
    {
      createTime:"2019/1/21/ 14:30:30",
      orderId: "1555555454",
      cilentName:"網(wǎng)三",
      cilentId:"21313216544",
      cilentPhone:"15576605432",
      cilentGrade:"1",
      orderPrice:"454664",
      orderState:"已提交",
      auditState: "系統(tǒng)已確認",
      receiver: "和大寶",
      phone:"16565644444",
      address:"廣東省深圳市*************************",
      orderRemark:"少放醋,多方唐撒旦啊阿薩大薩達"
      },
     ]};
    },
    methods: {
      // 初始頁currentPage、初始每頁數(shù)據(jù)數(shù)pagesize和數(shù)據(jù)data
      handleSizeChange: function (size) {
      this.pagesize = size;
      console.log(this.pagesize) //每頁下拉顯示數(shù)據(jù)
     },
      handleCurrentChange: function(currentPage){
        this.currentPage = currentPage;
        document.documentElement.scrollTop = 0;//點擊翻頁的時候回到頂部
        console.log(this.currentPage) //點擊第幾頁
      },
     },
  // 訂單列表搜索關(guān)鍵字
   computed: {
    orderList: function() {
    var _search = this.search;
    if (_search) {
      return this.Cashdata.filter(function(product) {
      return Object.keys(product).some(function(key) {
      return String(product[key]).toLowerCase().indexOf(_search) > -1
    })
  })
  }
    return this.Cashdata;
    }
  }
};
</script>

3.分頁的CSS只是自己修改的部分,如有需要,請自行腦補。對了,補充一句,修改Eleement樣式時,先在樣式前加 /deep/.最外層類名{......}。

<style lang="scss" scoped>
/deep/.el-pagination{
 margin-bottom: 30px;
 margin-top: 30px;
 float: right;
 font-size: 20px;
 color: #333333;
 margin-right: 55px;
 font-weight: normal;

 .el-select .el-input{
 width: 126px;
 height: 36px;
 }
 .el-select .el-input .el-input__inner{
 height: 100%;
 font-size: 20px;
 color: #333333;
 }
 .el-pagination__editor.el-input .el-input__inner{
 height: 36px;
 }
 .btn-prev,.btn-next{
 height: 36px;
 }
 .btn-prev{
 border-radius: 5px 0 0 5px;
 }
 .btn-next{
 border-radius: 0 5px 5px 0;
 }
 .el-pager li{
 line-height: 36px;
 height: 36px;
 font-size: 20px;
 }
 .el-pagination__total{
 color: #333333;
 }
 button,span:not([class*=suffix]){
 height: 36px;
 line-height: 36px;
 font-size: 20px;
 color: #333333;
 }
 .el-pagination__editor.el-input{
 font-size: 20px;
 }
 }
</style>

4.如有問題,歡迎指教。

附上效果圖一份:

Vue怎么實現(xiàn)分頁與輸入框關(guān)鍵字篩選功能

Vue的優(yōu)點

Vue具體輕量級框架、簡單易學(xué)、雙向數(shù)據(jù)綁定、組件化、數(shù)據(jù)和結(jié)構(gòu)的分離、虛擬DOM、運行速度快等優(yōu)勢,Vue中頁面使用的是局部刷新,不用每次跳轉(zhuǎn)頁面都要請求所有數(shù)據(jù)和dom,可以大大提升訪問速度和用戶體驗。

以上是“Vue怎么實現(xiàn)分頁與輸入框關(guān)鍵字篩選功能”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

vue
AI