vue+element-ui分页和删除组件的抽出

-----------MyTable.vue组件页面

<template> <div> <el-table :data="tableData" :default-sort="{prop:tableProp , order: tableOrder}" @sort-change="changes" border> <el-table-column v-for="(item,key) in tableKey" :key="key" :prop="item.value" :label="item.name" sortable></el-table-column> </el-table> <el-pagination name="fenye" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="currentPage" :page-sizes="[10, 15, 20]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total=total> </el-pagination> </div> </template> <script> export default{ name: 'mytable', data(){ return{ tableData: [], currentPage:1, pageSize:10, tableProp:this.tablep.prop, tableOrder:this.tablep.order, sort:1, total:0 } }, props:['tableKey','tablep'], methods:{ //table排序触发 changes({ column, prop, order }){ this.tableProp = prop; this.tableOrder = order; if(order !== 'descending'){ this.sort = 0; }else{ this.sort = 1; } this.tableChang(); return false; }, //修改每页条数触发 handleSizeChange(val) { this.currentPage = 1; this.pageSize = val; this.tableChang(); }, //翻页触发 handleCurrentChange(val) { this.currentPage = val; this.tableChang(); }, //更新table数据 tableChang(){ this.$post(this.tablep.url,{ pageSize: this.pageSize, current: this.currentPage, orderBy:this.tableProp, sort:this.sort }).then(res=>{ this.total = res.data.total; this.tableData = JSON.parse(JSON.stringify(res.data.list)); }) } } } </script>

 

------------调用MyTable组件

<template> <div class="container"> <sl-table :tableKey="tableKey" :tablep="tablep" ></sl-table> </div> </template> <script> import Table from '@/components/mytable'; export default { data () { return { tableKey: [{ name: '用户名', value: 'username' },{ name: '密码', value: 'password' },{ name: '昵称', value: 'othername' }], tablep:{ url:'后台数据接口', prop:'排序字段', order: 'descending' //descending为倒序aescending为正序 } } }, components: { 'sl-table': Table } } </script>

 

很简单的完成vue+elementui的分页界面

转载于:https://www.cnblogs.com/lqtbk/p/9635783.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值