效果圖:

訪問的數據量小,一次返回所有數據,再次利用elementUI-Table 和el-pagination組件進行展示,關鍵點事數據的篩選
官網的完整案例
<div class="block">
<span class="demonstration">完整功能</span>
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage4"
:page-sizes="[100, 200, 300, 400]" //顯示 5條/頁的值
:page-size="100"
layout="total, sizes, prev, pager, next, jumper" //分別對應了[共33條, 5條/頁,<.......>]
:total="400"> //設置總條數
</el-pagination>
</div>
<script>
export default {
methods: {
handleSizeChange(val) {
console.log(`每頁 ${val} 條`);
},
handleCurrentChange(val) {
console.log(`當前頁: ${val}`);
}
},
data() {
return {
currentPage1: 5,
currentPage2: 5,
currentPage3: 5,
currentPage4: 4
};
}
}
</script>
demo的使用
<el-table :data="list" style="width: 100%" @selection-change="selectItem"> <el-table-column type="selection" width="50"></el-table-column> <el-table-column label="用戶名" prop="userName" width="150"></el-table-column> <el-table-column label="用戶代碼" prop="userCode" width="150"></el-table-column> <el-table-column label="所屬機構代碼" prop="comCode" width="140"></el-table-column> <el-table-column label="用戶描述" prop="userDescription" width="300"></el-table-column> <el-table-column label="用戶狀態" align="center" prop="userState" width="100"> <template scope="scope"> <div> <!-- {{ scope.row.userState | userState }}--> {{scope.row.userState == 0 ? "啟用" : scope.row.userState == 1 ? "禁用" : "解鎖"}} </div> </template> </el-table-column> <el-table-column label="創建時間" prop="makeDate" width="140"></el-table-column> <el-table-column label="操作" width="200" align="center"> <template scope="scope"> <div> <span> <router-link :to="{ name: 'usersEdit', params: { id: scope.row.userCode }}" class="btn-link edit-btn"> 編輯 </router-link> </span> <span> <el-button size="small" type="danger" @click="confirmDelete(scope.row)">刪除</el-button> </span> </div> </template> </el-table-column> </el-table> <div class="pos-rel p-t-20"> <btnGroup :selectedData="multipleSelection" :type="'users'"></btnGroup> <div class="block pages"> <el-pagination @current-change="handleCurrentChange" @size-change="handleSizeChange" layout="total, sizes,prev, pager, next" :page-sizes="[1, 5,8, 10]" :page-size="limit" :current-page="page" :total="total"> </el-pagination> </div> </div>
接着設置data(){ }
data() {
return {
list:[],
tableData: [],
realname: '',
multipleSelection: [],
pagesize: 8,
page:1, //對應el-pagination current-page
limit:5, //和:page-size 對應
total:null, //和:total對應
}
},
請求數據
getAllUsers() {
this.loading = true
const data = {
params: {
realname: this.realname,
page: this.currentPage,
rows: this.limit
}
}//不要了這個是按后台分頁所需要的數據
this.apiGet('admincrud/users', data).then((res) => {
console.log('res = ', _g.j2s(res))
this.handelResponse(res, (data) => {
this.tableData = data.list
this.dataCount = data.total
this.pageList()
})
})
},
數據過濾
//處理數據
getList() {
//es6過濾得到滿足搜索條件的展示數據list
// let list2 = this.data.filter((item, index) =>
// item.name.includes(this.tableData)
// )
let list=this.tableData;
this.list = list.filter((item, index) =>
index < this.page * this.limit && index >= this.limit * (this.page - 1)
)
this.total = list.length
},
倆個按鈕事件的處理函數
// 當每頁數量改變
handleSizeChange(val) {
console.log(`每頁 ${val} 條`);
this.limit = val
this.getList()
},
// 當當前頁改變
handleCurrentChange(val) {
console.log(`當前頁: ${val}`);
this.page = val
this.getList()
},
vue+element實現前端分頁及前端搜索功能
主要他的這個搜索過濾挺好的簡單不要重新訪問后台,我自己沒時間改了,現在把思路過程放這里
見下一篇
atzhang
