vue分页组件

复制代码
<template>
  <div>
    <div class="block" style="margin: 2% 25%;">
            <el-pagination
                layout="total, prev, pager, next, jumper"
                :total="value.page"
                
                @prev-click="last"
                @next-click="next"
                @current-change="go"
                >
            </el-pagination>
        </div>
  </div>
</template>

<script>
export default {
    data(){
        return {
            currentPage:1,
        }
    },
    props:['value'],
    methods:{
        next(){
            this.currentPage+=1
            this.$emit('next',this.currentPage)
        },
        last(){
            this.currentPage-=1
            this.$emit('last',this.currentPage)
        },
        go(val){
            this.currentPage=val
            this.$emit('exchange',val)
        }
    },
    watch:{
        value(){
            this.currentPage = this.value.current_page
        }
    }
}
</script>

<style>

</style>
复制代码

 

复制代码
:data="dis"        

<to-page :value="{
            page : 表格行数,
            current_page:current_page
            }" 
                @exchange="exchange"
            ></to-page>


<script>
import ToPage from '组件路径'

export default {
  components: { ToPage },
    data() {
      return {
        current_page:1,
        dis:[]
      }
    },
    methods:{
        exchange(val){
            console.log(val)
            this.current_page = val
        }
    },
    mounted(){
        for (let i=0;i<30;i++)
            this.tableData.push(this.tableData[0])
        
        for (let i=this.current_page-1;i<10;i++)
            this.dis.push(this.tableData[i])
    },
    watch:{
        current_page(){
            this.dis = []
            for (let i=(this.current_page-1)*10;i<this.tableData.length;i++)
                this.dis.push(this.tableData[i])
            }
    }
}
</script>
复制代码

 

posted @   子过杨梅  阅读(26)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示