vue element ui分页演示demo 对接上后台数据就能用

自己写的分页demo 加上后台数据就可用

页面展示

 

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <!-- import CSS -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
	<script src="https://cdn.staticfile.org/vue/2.4.2/vue.min.js"></script>
	<script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>
</head>
<style>
#app {width:800px; margin:0 auto ;  }
</style>
<body>
  <div id="app"> 
   <template>
	<el-table  :data="arrData"  style="width: 100%">		
    <el-table-column  type="index" label="序号" :index="indexMethod" width="50"> </el-table-column>
    <el-table-column	prop="name"	label="姓名" width="180">  </el-table-column>
	</el-table>
	</template>   
	  <div class="block">
	   <el-pagination layout="prev, pager, next ,sizes, jumper" 			
			:page-count="pageCount" //总页数
            :page-size="pageSize" 
			:total="total" 		
			@current-change="currentChange" //点击第几页
			@prev-click="prevClick"         //上一页 点击上一页也调用 上面的currentChange事件 
			@next-click="nextClick"			//下一页 点击下一页也调用 上面的currentChange事件
			:page-sizes="[2, 5, 10, 20]" 	
			@size-change='sizeChange' //每页条数改变
			>
			</el-pagination>
    </div> 
	<el-button  @click="getData" >getData</el-button>
  </div>
</body>
  <!-- import Vue before Element -->
 
  <!-- import JavaScript -->
  <script src="https://unpkg.com/element-ui/lib/index.js"></script>
  <script>
 new Vue({
     el: '#app',
    data: function() {
    return { 		     
	  total: 0, // 总条数
	  pageCount:4,//总页数
	  pageNum: 1, // 第几页
	  pageSize: 10, // 每页显示的数量		 
	  url:'post.php',
	  arrData: [
        {"name": "编号0","age": 10},
        {"name": "编号1","age": 10},
        {"name": "编号2","age": 10},
        {"name": "编号3","age": 10},
        {"name": "编号4","age": 10},
        {"name": "编号5","age": 10},
        ]  //后台数据格式自己模拟就可以了
		}
      },	   
    methods: { 
    indexMethod(index) { //添加序号
        return (this.pageNum-1)*(this.pageSize)+index+1;
    },	  
    sizeChange:function(n){//每页条数改变
        this.pageSize=n								
        this.getData(this.pageNum,this.pageSize); 
        },
    getData: function (pageNum,pageSize) {	     
        this.pageNum=pageNum || this.pageNum;//如果没传值使用默认
        this.pageSize=pageSize || this.pageSize;
        this.$http.get(this.url,{params :{pageNum:pageNum,pageSize:pageSize}}).then(resp=>{  
            console.log(resp);	 
            this.arrData=resp.body.lists
            this.total = resp.body.total; // 总页数
        }).catch(resp =>{
            console.log('failure');
        })
    },
    currentChange:function(val){ //页码变更 点击第几页  包括了上一页下一页					 
        this.pageNum = val;
        this.pageSize = this.pageSize;
        this.getData(this.pageNum,this.pageSize);
        },	
    prevClick:function(val){ //上一页			
        console.log('上一页');
        },	
    nextClick:function(val){//下一页
        console.log('下一页');
        },	
    },
    mounted:function(){
    let pageNum=1;
        this.getData(pageNum,this.pageSize); 
    }		
		  
 })
  </script>
</html>

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值