vue+element-ui+ <el-table>的下标、序号、列表、tag标签分页功能

18 篇文章 0 订阅
1 篇文章 0 订阅

vue后台系统项目使用element-ui框架实现列表分页功能,获取用户列表数据。

效果:
在这里插入图片描述

页面:

<div class="deit">
    <div class="crumbs">
        <div class="cantainer">
             <el-table style="width: 100%;" :data="userList" align='center'>
                  <el-table-column type="index" label="序号" width="100" align="center"></el-table-column>
                  <el-table-column label="日期" prop="date" width="180"> </el-table-column>
                  <el-table-column label="姓名" prop="name" width="180"> </el-table-column>
 				  <el-table-column  label="地址">
				       <template slot-scope="scope">
				            <span style="margin-left: 10px">${ scope.row.address}</span>
				       </template>
				  </el-table-column>
				   {{-- 多个tag --}}
				   <el-table-column
				       label="国别"
				       width="120">
				       <template slot-scope="scope">
				           <template v-for="tag in scope.row.nations">
				               <el-tag :key="tag.name">
				                   ${tag.name}
				               </el-tag>
				           </template>
				       </template>
				   </el-table-column>
				   <el-table-column
					   prop="is_size"
				       label="是否分码"
				       width="80"
				       filter-placement="bottom-end">
				       <template slot-scope="scope">
				           <el-tag v-if="scope.row.is_size == 0"></el-tag>
				           <el-tag v-else></el-tag>
				       </template>
				   </el-table-column>
				   <el-table-column style="align: center" fixed="right" label="操作" width="200" align="center">
				     <template slot-scope="scope">
				          {{-- 权限控制 --}}
				       	 @if (\Encore\Admin\Facades\Admin::user()->can('editAction') || \Encore\Admin\Facades\Admin::user()->isAdministrator())
				       		<el-button @click="handleClick(scope.$index)" type="text" size="small" icon="el-icon-edit">编辑</el-button>
				       	 @endif
					     @if (\Encore\Admin\Facades\Admin::user()->can('delAction') || \Encore\Admin\Facades\Admin::user()->isAdministrator())
					       <el-button @click="deleteUserByUserName(scope.row,scope.$index)" type="text" size="small" icon="el-icon-delete" style="color: red">删除</el-button>
				    	 @endif
				     </template>
				   </el-table-column>

             </el-table>
             <el-pagination
                     background
                     @size-change="handleSizeChange"
                     @current-change="handleCurrentChange"
                     :current-page="currentPage"
                     {{-- 下拉框展示的分页条数 --}}
                     :page-sizes="[20, 30, 40]"
                     {{-- 显示当前行的条数  --}}
                     :page-size="pagesize"
                     layout="total, sizes, prev, pager, next, jumper"
                     :total="total">  <!-- 数据总数  -->
                 >
              </el-pagination>
        </div>
    </div>
  </div>
 

需要data中定义,userList接受接口返回的数据

delimiters: ['${', '}'],
data () {
      return {
          currentPage:1, //当前页
             pagesize:20,//分页的数据
             total: 0, //总页数
             userList: []
      }
  },

created() {
        this.handleUserList()
    },
    methods: {
        handleSizeChange(val) {
                this.pagesize = val;
                this.handleUserData();
        },
        handleCurrentChange(val){
            this.currentPage = val;
            this.handleUserData();
        },
        handleUserData() {
            //接口请求,传递分页参数
                let params = {
                        pageSize:this.pageSize,
                        currentPage:this.currentPage
                        //pageNum:this.pageNum
                }
            getUserList(params).then(res => {
                this.userList = res.data;
                this.total = res.total;
                //this.total = res.data.length;
            })
        },
        getUserList(){
            var that = this;
				$.ajax({
                    url: "/admin/cutting/getData",
                    type: "POST",
                    data:{
                        '_token': "{{ csrf_token() }}",
                        'search_word' : that.search_word,
                        'pageSize':that.pageSize,
                        'currentPage':that.currentPage,
                    },
                    dataType:'json',
                    success: function (res) {
                        if (res.code == 1) {
                            console.log(res)
                            that.datas = res.data;
                            that.total = res.total;
                        }else{
                            that.$alert(res.msg, '提示', {
                                confirmButtonText: '确定',
                                callback: action => {

                                }
                            });
                        }
                    }
                });
		}
    }
 

vue方法中获取el-table的下标和序号

  • type=“index”:就是显示序号
  • scope.$index:就是选中行的下标
  • scope.row:就是选中行的所有的信息
    例如:scope.row.name:获取姓名
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值