前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >在element-ui的基础上封装组件

在element-ui的基础上封装组件

作者头像
用户4344670
发布2019-11-04 02:40:07
9090
发布2019-11-04 02:40:07
举报
文章被收录于专栏:vue的实战vue的实战
代码语言:javascript
复制
///  通过props来把参数传递给父组件  page-size  在props接收的时候会自动的变成pageS
<template>
 <paging-query :totals="total" :page-size="pageSize" @handleSizeChangeSub="handleSizeChangeFun" @handleCurrentChangeSub="handleCurrentChangeFun"></paging-query>
  
  </div>
</template>
<script>
import PagingQuery from "@/components/paging-query";
export default {
  data() {
    return {
      total: 300,////   父组件把total 传递给子组件  :totalss="total"   那么子组件接收的就是totalss     子组件里面出发这个事件 handleSizeChangeSub
      pageSize: 0,
    
  },
  components: {
    PagingQuery
  },
  methods: {
  handleSizeChangeFun(v) {
    console.log(v);
  this.pageSize = v;
//   this._enterpriseList(); //更新列表
},

handleCurrentChangeFun(v) { //页面点击
  this.pageNum = v; //当前页
//   this._enterpriseList(); //更新列表
},

  }
};
</script>
<style>
</style>
  • 子组件
代码语言:javascript
复制
<template>
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :page-sizes="[10, 20, 30, 40]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="totals" style="float:right;">
    </el-pagination>
</template>
<script type="text/ecmascript-6">
export default {
    components: {

    },
    data() {
        return {

        }
    },
    props: {
// 接收父组件传递过来的值
        pageSize: {
            type: Number,
            default: 10
        },
        totals: {
            type: Number,
            default: 1
        }
    },
    watch: {

    },
    methods: {
        //每页展示条数
        handleSizeChange(val) {
            //事件传递    handleSizeChangeSub 是父组件定义的自定义事件
            this.$emit('handleSizeChangeSub', val);
        },
        //当前页
        handleCurrentChange(val) {
            //事件传递  在this.$emit的同时,携带参数
            this.$emit('handleCurrentChangeSub', val);
        }
    },
    // 过滤器设计目的就是用于简单的文本转换
    filters: {},
    // 若要实现更复杂的数据变换,你应该使用计算属性
    computed: {

    },
    created() {

    },
    mounted() {},
    destroyed() {}
}
</script>
<style lang="" type="text/css" scoped>
</style>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档