vue+element ui 写分页器

分页器vue+element ui

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>分页器</title>

</head>
<style type="text/css">
    html {
        width: 100%;
        height: 100%;
        background-color: white;
    }

    body {
        margin: 0;
        padding: 0;
        height: 100%;
        border: 0;
        overflow: hidden;
    }

    .el-form-item__content {
        line-height: 23px !important;
    }

    .flexToOne {
        height: 20px;
    }
</style>

<body>
    <div id="app" style="padding: 15px;">
        <div class="form-box marginB20">
            <el-form :model="ruleForm" ref="loginFormRef" inline-message ref="ruleForm" label-position="top"
                label-width="100px" class="demo-ruleForm">
            </el-form>
        </div>
        <el-table  :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)" 
        border v-loading="loading" :height="tableHeight">
            <el-table-column type="index" align="center" fixed="left" label="序号" width="100">
                <template slot-scope="scope">
                    <div v-text="(currentPage-1)*pagesize+1+scope.$index"></div>
                </template>
            </el-table-column>
            <el-table-column align="center"  label="日志log" >
                <template slot-scope="scope">
                    <div v-text="tableData[(currentPage-1)*pagesize+scope.$index]"></div>
                </template>
            </el-table-column> 
            <el-table-column  align="center" label="地址ip" width="300">
                <template slot-scope="scope">
                    <div v-text="tableDataa[(currentPage-1)*pagesize+scope.$index]"></div>
                </template>
            </el-table-column>
            <el-table-column  align="center" label="操作" width="250">
            </el-table-column>
        </el-table>
        <!-- 分页器 -->
        <el-pagination style="text-align: right;margin-top: 10px;" small @current-change="handleCurrentChange"
            background @size-change="handleSizeChange" background   :current-page="currentPage"
            :page-size="pagesize"
            :page-sizes="[10, 20, 30, 40]"
            :total="tableData.length" layout="total,sizes, prev, pager, next, jumper">
        </el-pagination>
    </div>
</body>

<script>
    new Vue({
        el: '#app',
        data: function () {
            return {
                
                currentPage: 1, //当前页
                pagesize: 10,   //显示条
                tableHeight: "300px",
                tableData: [],   //log日志
           
            }
        },
        methods: {
               // 日志监控列表数据渲染 
            toList() {
                var that = this
                that.loading = true;
                axios.get(api.logmonitoring,
                    {
                    }).then(function (response) {
                        that.loading = false;  //隐藏loading图标
                        console.log(response.data.data);
                        var Ipconfig = [];
                        for (var i in response.data.data.address) {
                            Ipconfig.push(response.data.data.address)
                        }

                        that.tableData= response.data.data.allLogList //log日志
                        console.log(that.tableData);
                        that.tableDataa= Ipconfig  //ip地址
       
                    })
                    .catch(function (error) {
                        console.log(error);
                    });
            },
            //设置条数触发事件 
            handleSizeChange: function (val) {
              console.log(`每页:${val}条`);
                this.pagesize = val
                console.log(1111111);
                console.log(this.pagesize);
                
            },
            //设置当前页触发事件
            handleCurrentChange: function (currentPage) {
                console.log(`当前页: ${currentPage}`);
                this.currentPage = currentPage
                console.log(22222222);
                console.log(this.currentPage);
            },
        },
        created() {
           
            //获取日志监控列表
            that.toList();
        },
    })
</script>

</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是使用Vue3和Element UI实现分页的示例代码: ```vue <template> <div> <el-pagination :current-page="currentPage" :page-sizes="[10, 20, 30, 40]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total" @current-change="handleCurrentChange" @size-change="handleSizeChange" /> </div> </template> <script> import { ref } from 'vue'; import { ElPagination } from 'element-plus'; export default { components: { ElPagination, }, setup() { const currentPage = ref(1); const pageSize = ref(10); const total = ref(0); function handleCurrentChange(val) { currentPage.value = val; fetchData(); } function handleSizeChange(val) { pageSize.value = val; currentPage.value = 1; fetchData(); } function fetchData() { // 在这里发起请求获取分页数据 // 请求参数包括 currentPage.value 和 pageSize.value // 请求成功后更新 total.value 和分页数据 } fetchData(); return { currentPage, pageSize, total, handleCurrentChange, handleSizeChange, }; }, }; ``` 在这个示例中,我们使用了Vue3的Composition API来管理组件状态。我们使用了`ref`函数来创建响应式变量,这些变量包括当前页码、每页显示的条目数和总条目数。我们还使用了Element UI的`ElPagination`组件来渲染分页,并监听了`current-change`和`size-change`事件来处理页码和每页显示条目数的变化。在`handleCurrentChange`和`handleSizeChange`函数中,我们更新了当前页码和每页显示条目数,并重新发起了请求获取分页数据。在`fetchData`函数中,我们可以发起请求获取分页数据,并更新总条目数和分页数据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

张清悠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值