vue+iview實(shí)現(xiàn)分頁(yè)及查詢功能
vue+iview 分頁(yè)及刪、查功能實(shí)現(xiàn),供大家參考,具體內(nèi)容如下
首先要想實(shí)現(xiàn)分頁(yè)功能必須得知道 當(dāng)前頁(yè)碼、每頁(yè)大小、總數(shù)目。
iview對(duì)分頁(yè)的功能支持還是很強(qiáng)大的,有很多鉤子函數(shù)
具體實(shí)現(xiàn)看后端返回的數(shù)據(jù)
<template> <div v-if="this.$store.state.user.userType == 0 || this.$store.state.user.userType == 1"> <Input type="text" search enter-button placeholder="根據(jù)施工人員姓名查找" v-model="peopleName" @input="search"/> <Table width="100%" :columns="peopleCol" :data="peopleDat"></Table> <!--通過(guò)sync修飾符可以動(dòng)態(tài)獲取頁(yè)碼--> <Page :total="dataCount" :current.sync="current" :page-size="pageSize" show-total class="paging" @on-change="changePage"></Page> <!--該modal是刪除提醒框--> <Modal v-model="confirmDelete" width="360"> <p slot="header" style="color:#f60;text-align:center"> <Icon type="ios-information-circle"></Icon> <span>刪除確認(rèn)</span> </p> <div style="text-align:center"> <p>此操作不可恢復(fù),確定要?jiǎng)h除嗎?</p> </div> <div slot="footer"> <Button size="large" @click="cancelDelete">取消</Button> <Button type="error" size="large" @click="deleteConfirm">刪除</Button> </div> </Modal> </div> </template> <script> export default { components: { addWorker, updateWorker }, data () { return { selectedID:'',//刪除選中的ID confirmDelete:false,//刪除提示框 current:1, isShow:false, selectedList:{},//選中施工人員的id值 peopleName:'', dataCount:0,//總條數(shù) pageSize:2,//每頁(yè)顯示數(shù)據(jù)條數(shù) peopleDat: [], peopleCol: [ { title: '操作', key: 'action', width: 120, render: (h, params) => { return h('Button', { props: { type: 'error', size: 'small' }, on:{ click: ()=>{ this.confirmDelete=true this.delete(params.row.peopleID) } } }, '刪除') } } ], } }, mounted() { this.getWorkerList() }, methods:{ getWorkerList(){//組件初始化顯示的數(shù)據(jù) const currPage=1 const pageSize=this.pageSize //下面是向后臺(tái)發(fā)送請(qǐng)求 setTimeout(async()=>{ const r=await getWorkers(currPage,pageSize) if(r.data.success){ this.dataCount=r.data.list.count//初始化總條數(shù) this.peopleDat=r.data.list.data//默認(rèn)頁(yè)列表渲染數(shù)據(jù) console.log(r) } }) }, changePage(index){//頁(yè)碼改變觸發(fā)的函數(shù) //index當(dāng)前頁(yè)碼 const currPage=index const pageSize=this.pageSize setTimeout(async ()=>{ const r=await changePage(currPage,pageSize) if(r.data.success){ this.peopleDat=r.data.list.data//當(dāng)前頁(yè)列表數(shù)據(jù) } }) }, search(){ const peopleName=this.peopleName const pageSize=this.pageSize setTimeout(async()=>{ const r=await search(peopleName,pageSize) if(r.data.success){ this.peopleDat=r.data.list.data this.dataCount=r.data.list.count//如果不設(shè)置總條數(shù)那么當(dāng)精確查詢時(shí)每頁(yè)都會(huì)有數(shù)據(jù)這得看后端返回的數(shù)據(jù)有沒(méi)有這些數(shù)據(jù) } else { this.$Message.warning('查詢失敗!') } }) }, delete(peopleID){ this.selectedID=peopleID }, deleteConfirm(){ const id=this.selectedID setTimeout(async ()=>{ const r=await deleteWorker(id) if(r.data.success){ //這里做的一個(gè)功能是當(dāng)你刪除某頁(yè)數(shù)據(jù)后立即刷新當(dāng)前頁(yè)的數(shù)據(jù) this.changePage(this.current)//更新當(dāng)前頁(yè)碼的數(shù)據(jù) this.$Message.success('刪除成功!') } else{ this.$Message.warning('刪除失敗!') } }) this.confirmDelete=false }, cancelDelete(){ this.confirmDelete=false this.$Message.info('你取消了刪除操作') } } } </script> <style scoped> .paging{ float:left; margin-top:10px; } </style>
關(guān)于vue.js的學(xué)習(xí)教程,請(qǐng)大家點(diǎn)擊專題vue.js組件學(xué)習(xí)教程、Vue.js前端組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue2.0實(shí)現(xiàn)前端星星評(píng)分功能組件實(shí)例代碼
本文通過(guò)實(shí)例代碼給大家介紹了vue2.0實(shí)現(xiàn)前端星星評(píng)分功能組件,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧2018-02-02Vue在頁(yè)面右上角實(shí)現(xiàn)可懸浮/隱藏的系統(tǒng)菜單
這篇文章主要介紹了Vue在頁(yè)面右上角實(shí)現(xiàn)可懸浮/隱藏的系統(tǒng)菜單,實(shí)現(xiàn)思路大概是通過(guò)props將showCancel這個(gè)Boolean值傳遞到子組件,對(duì)父子組件分別綁定事件,來(lái)控制這個(gè)系統(tǒng)菜單的顯示狀態(tài)。需要的朋友可以參考下2018-05-05vue2.0如何動(dòng)態(tài)綁定img的src屬性(三元運(yùn)算)
這篇文章主要介紹了vue2.0如何動(dòng)態(tài)綁定img的src屬性(三元運(yùn)算)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-08-08vue-cli5.0?webpack?采用?copy-webpack-plugin?打包復(fù)制文件的方法
今天就好好說(shuō)說(shuō)vue-cli5.0種使用copy-webpack-plugin插件該如何配置的問(wèn)題。這里我們安裝的 copy-webpack-plugin 的版本是 ^11.0.0,感興趣的朋友一起看看吧2022-06-06vant?Cascader級(jí)聯(lián)選擇實(shí)現(xiàn)可以選擇任意一層級(jí)
這篇文章主要介紹了vant?Cascader級(jí)聯(lián)選擇實(shí)現(xiàn)可以選擇任意一層級(jí)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-07-07vue播放flv、m3u8視頻流(監(jiān)控)的方法實(shí)例
隨著前端大屏頁(yè)面的逐漸壯大,客戶的...其中實(shí)時(shí)播放監(jiān)控的需求逐步增加,視頻流格式也是有很多種,用到最多的.flv、.m3u8,下面這篇文章主要給大家介紹了關(guān)于vue播放flv、m3u8視頻流(監(jiān)控)的相關(guān)資料,需要的朋友可以參考下2023-04-04