記錄:vue結合springboot進行分頁查詢和按條件進行查詢


界面:

 

 

主要代碼:

搜索框:

    <el-form ref="searchForm" :inline="true" :model="searchMap" style="margin-top: 20px;margin-left: 0px"
    >
      <el-form-item prop="companyName">
        <el-input v-model.lazy="searchMap.companyName">
          <template slot="prepend">公司名稱</template>
        </el-input>
      </el-form-item>
      <el-button @click="searchcompany" icon="el-icon-search"></el-button>
    </el-form>
 <el-button @click="searchcompany" icon="el-icon-search"></el-button>

綁定按鈕的事件為:searchcompany(根據公司名稱進行查詢)

    searchcompany() {
      this.currentPage = 1;  // 賦值1是為了查詢時,由頁面1開始查詢,避免查詢不到數據的情況,以后想到更好的辦法再優化
      this.searchBycompanyName();
    },
    // 根據公司名稱查詢
    searchBycompanyName() {
      resourcemgApi
        .zyCompanySearchByName(this.searchMap.companyName, this.currentPage, this.pageSize)
        .then(resp => {
          this.list = resp.data.rows;
          this.total = resp.data.total;
          console.log(resp);
        });
    }, 

 

分頁按鈕部分:

    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[5,10,20,30]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"
    ></el-pagination>

分別綁定兩個事件:

handleSizeChange:改變每頁的數據條數

handleCurrentChange:改變當前頁碼

    // 當每頁顯示條數改變后,被觸發,val是最新的顯示條數
 handleSizeChange(val) { console.log(`每頁 ${val} 條`); this.pageSize = val; this.searchBycompanyName();
 }, // 當頁碼改變后,被觸發,val是最新的頁碼
 handleCurrentChange(val) { console.log(`當前頁: ${val}`); this.currentPage = val; this.searchBycompanyName();
    },

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM