element-ui表格的表头使用类似下拉框样式

记录elementui表格中表头插入下拉小指标的方法.

<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>表格</span>
      </div>
      <div class="content">
        <template>
          <el-table
            @selection-change="handleSelectionChangeUsers"
            :data="tableData"
            style="width: 100%">
            <el-table-column
              label="Date"
              prop="date">
            </el-table-column>
            <el-table-column
              label="Name"
              prop="name">
            </el-table-column>
            <el-table-column
              prop="flag"
              align="center">
              <template slot="header" slot-scope="scope">
                <el-dropdown trigger="click" @command="handleCommand" size="mini">
                  <span>
                    {{ tableTitle }}<i class="el-icon-arrow-down el-icon--right"></i>
                  </span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item v-for="item in jobs"
                      :key="item.id" :command="item.label">
                      {{item.label}}
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </div>
    </el-card>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        tableData: [{
          date: '平安',
          name: '27%',
          address: '45%',
          flag: '12'
        }, {
          date: '市场',
          name: '27%',
          address: '45%',
          flag: '12'
        }, {
          date: '同业-R',
          name: '27%',
          address: '45%',
          flag: '12'
        }, {
          date: '同业-T',
          name: '27%',
          address: '45%',
          flag: '12'
        }],
        search: '',
        jobs: [
          {
            label: '整体',
            value: 'ZT',
          },
          {
            label: '车',
            value: 'C',
          },
          {
            label: '飞车',
            value: 'FC',
          },
          {
            label: '餐险',
            value: 'CX',
          },
        ],
        tableTitle: '整体',
      }
    },
    methods: {
      handleCommand(command) {
        console.log(command);
        this.tableTitle = command;
        this.tableData = [{
          date: '哈哈',
          name: '27%',
          address: '45%',
          flag: '12'
        }, {
          date: '啦啦',
          name: '27%',
          address: '45%',
          flag: '12'
        }, {
          date: '阻止',
          name: '27%',
          address: '45%',
          flag: '12'
        }, {
          date: '变v',
          name: '27%',
          address: '45%',
          flag: '12'
        }];
      },
      handleSelectionChangeUsers() {
        console.log('变了');
      }
    },
  }
</script>

<style lang="less" scoped>
</style>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值