這篇文章主要為大家詳細介紹了vue+iview實(shí)現分頁(yè)及查詢(xún)功能,實(shí)現文中示例代碼介紹的分頁(yè)非常詳細,具有一定的及查參考價(jià)值,感興趣的詢(xún)功小伙伴們可以參考一下
vue+iview 分頁(yè)及刪、查功能實(shí)現
首先要想(xiang)實(shí)現分頁(yè)功能必須得知道 當前頁(yè)碼、實(shí)現每頁(yè)大小、分頁(yè)總數目。及查
iview對分頁(yè)的詢(xún)功功能支持還是很強大(da)的,有(you)很多鉤子函數
具(′?_?`)體實(shí)現看后端返回的實(shí)現數據
<template>
<div v-if="this.$store.state.user.userType == 0 || this.$store.state.use┐(′?`)┌r.userType == 1">
<Input type="text" search enter-button placeholder='根據施工人員姓名查找' v-model='peopleName' @input='search'/>
<Table width='100%' :columns="peopleCol" :data='peopleDat'></Table>
<!--通過(guò)sync修飾符可以動(dòng)態(tài)獲取頁(yè)碼--&(′▽?zhuān)?gt;
<Page :total='dataCount' :current.sync="current" :page-size="pageSize" show-total class="paging" @on-change="changePage"></Page>
<!--該modal是刪除提醒(??-)?框-->
<Modal v-m??odel="confirmDelete" width="360">
<p slot="he(╥_╥)ader" style='color:#f60;te(′?_?`)xt-align:center'>
<Icon type="ios-informatioヾ(^-^)ノn(′▽?zhuān)?)-circle"></Icon>
<span>刪除確認</span>
</p>
<div style="text-align:center"??>??;
<p>此操作不可恢復,確定要刪除??嗎?分頁(yè)</p>
</div>
<div slot='footer'>
<Button size="large" @click='cancelDel???ete'>取消</Button>
<Button type="error" size="large" @click='deleteConfirm'>刪除</Button>
</div>
</Modal>
</div>
</template>
<??script&g??t;
expor(╥_╥)t default {
components: {
addWorker,
updateWorker
},
data () {
return {
selected="selected"ID:'',//刪除選中的ID
confirmDelete:fal??se,//刪除提示框
current:1,
isShow:false,
selected='selected'List:{ },//選中施工人員的id值
peopleName:'',
dataCount:0,//總條數
pageSize:2,//每頁(yè)顯示數據條數
peopleDat: [],
peopleCol: [
{
title: '操作',
key: 'ac??tion',
width: 120,
render: (h, params) => {
return h('Button', {
props: {
type: 'er?ror',
size: 'small'
},
on:{
click: ()=>{
this.confirmDelete=true
this.delete(params.row.peopleID)
}
}
}, '刪除')
}
}
],
}
},
mounted() {
this.ge??tWorkerL?ヽ(′?`)ノist()
},
methods:?{
getWorkerList(){ //組件初始化顯示的數據
const currPage=1
const pageSize=this.pageSize
//下面是(′?`)向后臺發(fā)送請求
setTimeout(async()=>(?????);{
const r=await getWorkers(currPage,page??Size)
if(r.data.success){
this.dataCount=r.data.list.count//初始化總條數
this.peopleDat=r.data.l??ist.da??ta//默認頁(yè)列表渲染數據
console(//ω//).log(r)
}
})
},
changePage(index){(′▽?zhuān)?) //頁(yè)碼改變觸發(fā)的函數
//index當前頁(yè)碼
con??st currPage=index
const pageSize=this.pageSize
setTimeout( ???)(async ()=>{
const r=await changePage(currPage,pageSize)
if(r.data.success){
this.peopleDat=r.data.list.data//當前頁(yè)列表數據
}
})
},
search(){
const peopleNaヽ(′ー`)ノme=this.peopleName
const pageSize=???this.pageSize
setTimeout(asy??nc()=>{
const r=await se??arch(peopleName,pageSize)
if(r.data.success){
this.peopleDat=r.data.list.data
this.dataCount=r.data.list.count//如果不設置總條數那么當精確查詢(xún)時(shí)??每頁(yè)都會(huì )有數據這得看后端返回的數據有沒(méi)有這些數據
} else {
this.$Message.warning('查詢(xún)失敗!')
}
})
},
delete(peopleID){??
this.sel??ectedID=peopleID
},
deleteConfirm(){
const id=this.selected=""ID
setTimeout(async ()=>{
const r=await deleteWorker(id)
if(r.data.success){
//這里做的一個(gè)功能是當你刪除某頁(yè)數據后立即刷新當前頁(yè)的數據
this.changePage(this.cu???rrent)//更新當前頁(yè)碼的數據
this.$Message.success('刪除成功!')
} else{
thiヽ(′▽?zhuān)?ノs.$Message.warning('刪除失敗!')
}
})
this.confirmDelete=false
},
cancelDelete(){
this.confirmDelete=false
this.$Message.i(′?`)nfo('你取消了刪除操作')
}
}
}
</script&g??t;
<(?????);style scoped>
.pagi(′?`)ng{
float:left;
margin-top:10px;
}
</style>
關(guān)于vue.js的學(xué)習教程,請大家點(diǎn)擊專(zhuān)題vue.(′?`*)js組件學(xué)習教程、及查Vue.js前端組件學(xué)習教程進(jìn)行學(xué)習。詢(xún)功
以上就是實(shí)現本文的全部?jì)热?,希望對大家的分?yè)學(xué)習有所幫助,也希望大家多多支持腳本之家。及查
來(lái)源:腳本之家
鏈接:https://www.jb51.net/article/199911.htm