iview的table:自定義table表格中列頭的標題和點擊事件(renderHeader)


 <Table
           class="table"
           :columns="columns1"
           :data="tableData"
           highlight-row
           :max-height="500"
           border
           @on-selection-change="onSelectionChange"
           @on-row-click="onRowClick"
    >
      <!-- 重量 -->
      <template slot-scope="{ row, index }" slot="weight">
        <Input v-model="tableData[index].weight" placeholder="請輸入..." class="form-width" />
      </template>
    </Table>
 
 
columns1: [
          {
            title: '重量',
            slot: 'weight',
            align: 'center',
            key: 'weight',
             renderHeader: (h, params)  => {
              return h('div',[
                h('span', {}, '重量'),
                h('Icon', {
                  props: {
                    type: 'ios-copy-outline',
                    size: '18'
                  },
                  on: {
                    'click': (event) => {
                      this.weightCopy(event);
                    }
                  }
                })
              ])
            },
          }
        ],
 
  // 重量值拷貝功能
      weightCopy(e){
        if (this.tableData.length && this.tableData[0].weight) {
          this.tableData.map((item, index) => {
            this.tableData.splice(index, 1, {
              ...item,
              weight: this.tableData[0].weight
            })
          })
        } else {
          this.$Message.warning('第一行值為空,不能復制!')
        }
      },


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM