Element-ui自定義表頭,render-header+Scoped slot

Scoped slot

Element-ui 版本2.13.2 Table 組件中,可以通過設(shè)置 Scoped slot 來自定義表頭。

<template>
  <el-table>
    <el-table-column align="center" width="180px">
      <template slot="header" slot-scope="scope">
        <el-button  class="btn" @click="add(scope.row,)">表頭按鈕</el-button>
      </template>
      <template slot-scope="scope">
        <el-button @click="handleEdit(scope.$index, scope.row)">內(nèi)容按鈕</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

:render-header

低版本的Table 并不支持Scoped slot,但是el-table-column提供了render-header屬性,官方介紹:

//列標題 Label 區(qū)域渲染使用的 Function
Function(h, { column, $index })
參數(shù)h

h(param1, param2, param3)
param1: 元素的標簽名
param2: 對象,里面是一些class等屬性
param3: 數(shù)組,包含的子組件

樣例
<template>
<el-table>
    <el-table-column label="表頭按鈕" align="center" width="180px" :render-header="renderHeader">
        <template slot-scope="scope">
            <el-button @click="handleEdit(scope.$index, scope.row)">內(nèi)容按鈕</el-button>
        </template>
    </el-table-column>
</el-table>
</template>
data() {
  return {
  }
},
methods: {
  renderHeader(h, {column}){
        return h(
                   'div',{
                           style: 'margin-left: 10px;',
                   },[
                         h('el-button', {
                             style: 'margin-left: 5px;',
                             on: {
                                 click: ()=>{
                                     this.changeA()
                                 }
                             }
                         },[
                             column.label
                         ]),
                   ])
  },
}
效果
a.png

補充

MessageBox用法

MessageBox.confirm(
  h('div', null, [
    h('p',{style:'font-size:18px'},'請注意:'),
  ]),
  '', {
    cancelButtonText: this.$t('iphone.cancel'),
    confirmButtonText: this.$t('iphone.confirm'),
    customClass: 'tips_info',
    cancelButtonClass: 'tips_cancel',
    closeOnClickModal: false
 }).then((d)=>{}).cache((err)=>{})

結(jié)束語

應(yīng)該迭代版本

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容