el-row 源码解析

export default {

  name: 'ElRow',

  componentName: 'ElRow', // 自定义的组件名

  props: {

    tag: { // 自定义的标签名,后面用来进行render 函数的渲染

      type: String,

      default: 'div'

    },

    gutter: Number, // 栅格布局,是用来指定 子元素 el-col的间距

    type: String, // 布局默认,可选的是 flex

    justify: {

      type: String,

      default: 'start' // flex 布局

    },

    align: String // flex布局

  },

  


  computed: {

    style() { // 使用计算属性生成style

      const ret = {};
 
      if (this.gutter) {

        ret.marginLeft = `-${this.gutter / 2}px`;

        ret.marginRight = ret.marginLeft;

      }

      return ret;

    }

  },

  


  render(h) {  // render函数

    return h(this.tag, {

      class: [

        'el-row',

        this.justify !== 'start' ? `is-justify-${this.justify}` : '',

        this.align ? `is-align-${this.align}` : '',

        { 'el-row--flex': this.type === 'flex' }

      ],

      style: this.style

    }, this.$slots.default); // 默认插槽的虚拟dom

  }

};

这里主要是关注render 函数的使用,使用了this.$slots.default 奇妙的把插槽元素进行render.

以及上面绑定class的操作

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值