vue + iView:table 组件中 render 怎么绑定click事件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hongc93/article/details/85011705
tableData:{
    col: [{
      prop: 'name',
      label: '客户名称',
      align: 'left',
      minWidth: '150'
    },
    {
      prop: 'customerVal',
      label: '客户价值',
      align: 'left',
      width: '150'
    }],
    data:[
        {
          name: '南通长江汽车贸易有限公司',
          customerVal: 'A类客户'
        }
    ]
}
//方法1:
  testMethod(params) {
      console.log(params);
    },
 renderSweep() {
   this.tableData.col.forEach((item, index) => {
     if (item.prop == 'name') {
       item.render = (h, params) => {
         const test=()=>{
           this.testMethod(params.row)
         }
         return (<el-button type="text" onClick={test}>{params.row[item.prop]}</el-button>)
        }
      }
   }
}
//方法2:
renderSweep2() {
    if (item.prop == 'customerVal') {
        item.render=(h,params)=>{
            return h('el-button',{
                attrs:{
                    type:'text'
                },
                on:{
                    click:()=>{
                      this.test(params.row)
                    }
                }
            },params.row[item.prop])
        }
    }
}

猜你喜欢

转载自blog.csdn.net/hongc93/article/details/85011705