Ant design vue框架,table控件中customRow用法的一个坑

Ant design vue框架中,table控件中customRow用法的一个坑

今天在写代码时,用到Ant design框架中的<a-table>控件,其中的一个需求是:点击table中的一行,需要执行一些操作。因为没有默认的行点击事件,需要用到customRow来进行自定义。
这个方法,在官方的文档中,有使用说明,如下:
<Table
  customRow={(record) => {
    return {
      props: {
        xxx... //属性
      },
      on: { // 事件
        click: (event) => {},       // 点击行
        dblclick: (event) => {},
        contextmenu: (event) => {},
        mouseenter: (event) => {},  // 鼠标移入行
        mouseleave: (event) => {}
      },

    };
  )}
  customHeaderRow={(column) => {
    return {
      on: {
        click: () => {},        // 点击表头行
      }
    };
  )}
/>
官方的这个写法,应该是属于lamada的语法,今天我在使用时,也是使用这种写法。
如下:
methods:{
		getDetailList(id){
				//执行具体的操作
			},
		rowClick: (record, index) => ({
  	    // 事件
  	    on: {
     	   click: event => {
     	     // 点击该行时要做的事情
     	     console.log('record', record)
     	     console.log('index', index)
     	     console.log('event', event)
   	       this.getDetailList(record.id)  //这一行会报错,报未定义
    	    }
	      }
  	  })
    }

在执行时,会报错,如下:
[Vue warn]: Error in v-on handler: “TypeError: Cannot read property ‘getDetailList’ of undefined”。
不使用lamada表达式,则不会出现这样的问题,修改后的rowClick方法如下:

rowClick(record, index) {
      return {
        on: {
          click: () => {
            console.log(record, index)
            this.getDetailList(record.matbillid)
          }
        }
      }
    },

可正常执行,并能正确调用getDetailList方法

  • 4
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值