天天看點

Element Pagination 分頁請求兩次接口BUG解決--測試可用!!!

前言:element Ui 分頁size-change事件觸發同時也出發了current-change事件

bug:當選擇最後至一頁切換條數就會請求兩次接口

1:選擇最後一頁(第2頁)

Element Pagination 分頁請求兩次接口BUG解決--測試可用!!!

2:切換條數會請求兩次接口

Element Pagination 分頁請求兩次接口BUG解決--測試可用!!!

解決方法:定義變量state預設為true;條數改變的時候@current-change事件則不請求接口,這樣的話隻請求了@size-change事件的接口請求、

<el-pagination center background :pager-count="5" layout="prev, pager, next, sizes" :page-sizes="[10,20,50]"
  :page-size="pagesize" :total="total" @current-change="handleCurrentChange" @size-change="handleSizeChange">
</el-pagination>
           
data(){
	return{
		dataObj: {
          token: this.$store.getters.token,
          index: 1,
          length: 10
        },
        total:0,
        currpage: 1,
        pagesize: 10,
        total:0,//條數的總數
		state:true,
	}
}
           
methods:{
	getData() {
		接口請求....
		api().then(res=>{
			請求成功...
			this.state=true;
			this.total = res.max;	//條數的總數
		})
	},
	handleCurrentChange(cpage) {  //頁數
        // console.log(cpage)
        this.currpage = cpage;
        this.dataObj.index = cpage;
        if(this.state==true){
          this.getData()
        }
      },
      handleSizeChange(psize) {   //條數
        // console.log(psize)
        this.state=false;
        this.pagesize = psize;
        this.dataObj.length = psize
        if(this.state==false){
          this.getData()
        }
      },
}
           

繼續閱讀