Ant-Design-Vue表格合并单元格,在customRender属性中添加标签和点击事件

参考文章:http://t.csdn.cn/CL9kz

问题:找不到$createElement

1、阅读大神的代码后到自己项目中使用时报错,如下

 2、报错代码片段

{
          title: '项目名称',
          align: 'center',
          dataIndex: 'proName',
          scopedSlots: { customRender: 'proName' },
          customRender: function(t, r, index){
            const child = this.$createElement('a', {
              domProps: {
                innerHTML: t
              },
              on: {
                click: function() {
                  this.customHandleDetail(r)
                }
              }
            })
            const obj = {
              children: child,
              attrs: {}
            }
            if (r.sortNum === '小计' || r.sortNum === '合计' || r.sortNum === '说明') {
              obj.attrs.colSpan = 0
            }
            return obj
          }

3、修改后

{
          title: '项目名称',
          align: 'center',
          dataIndex: 'proName',
          scopedSlots: { customRender: 'proName' },
          customRender: (t, r, index) => {
            let _this = this
            const child = _this.$createElement('a', {
              domProps: {
                innerHTML: t
              },
              on: {
                click: function() {
                  _this.customHandleDetail(r)
                }
              }
            })
            const obj = {
              children: child,
              attrs: {}
            }
            if (r.sortNum === '小计' || r.sortNum === '合计' || r.sortNum === '说明') {
              obj.attrs.colSpan = 0
            }
            return obj
          }
        },

4、总结

原因是我在使用customRender属性时没有使用箭头(=>)函数,而是使用了function,从而导致this找不到。具体=>与function的this指向问题请自行百度。

 

 

 

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值