有这样一个需求   element +vue 实现显示的table 的表头添加一个添加图标, 并绑定一个点击事件,我查了好多资料, 终于找到table 表头的一个事件  :render-header 可以实现。

 

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

 

代码html 

 

              <el-table-column fixed="left" width="65px"  :render-header="renderHeader">
                        <template slot-scope="scope">
                            <el-button @click.native.prevent="deleteRow(scope.$index, formDetail.taxEntityList)"
                                       size="small"><i class="el-icon-remove-outline"></i></el-button>
                        </template>
                    </el-table-column>
                </el-table>

  js:

methods: {
renderHeader(h, { column, $index }){
return h('div', null,[
h('span',null,[
h('i',{class :'el-icon-circle-plus-outline', on:{
click: function () {
vm.addRow();
}
}},''
)
]),

])
}
}

  js的意思 就是 添加 一个div 里面有个span  , span里面加一个<i class="el-icon-circle-plus-outline"></i>图片的class,on 后面的是绑定一个点击事件。注意返回的h(),第三个参数是个数组,就好似一个div里面有多个标签;

      蓝色的意思是每一行 有一个删除图片的按钮, 点击 删除

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄