本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长


+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

2024-11(1)

vxe-table(vxe-grid)自定义模块:列头

发布于2021-11-20 16:40     阅读(1570)     评论(0)     点赞(8)     收藏(1)


自定义列头模块

文档官网:https://xuliangzhan_admin.gitee.io/vxe-table/#/table/start/install

在列头上,有时候显示的title信息并不能满足我们想要显示的内容,这个时候查看文档,发现了自定义模块,使用插槽可以帮助我们实现自定义模板内容
在这里插入图片描述

使用slots

在插槽内容可以自定义模板,用css设置显示的样式

<template>
  <div>
    <vxe-grid border show-overflow ref="xGrid" height="500">
      <template #name_header="{ column }">
        <div class="slotBox">
          <p class="titleBox1">{{ "@" }}</p>
          <p class="titleBox2">{{ column.title }}</p>
        </div>
      </template>
    </vxe-grid>
  </div>
</template>
<script>
// import axios from 'axios'
// import request from '../libs/request'
export default {
  data () {
    return {
      loading: false
    }
  },
  created () {
    this.loadColumnAndData()
  },
  methods: {
    loadColumnAndData () {
      this.loading = true
      Promise.all([this.mockColumns(), this.mockList()]).then((rest) => {
        const columns = rest[0]
        const data = rest[1]
        const startTime = Date.now()
        const xGrid = this.$refs.xGrid
        console.log(xGrid)
        // 使用函数式加载,阻断 vue 对大数组的双向绑定
        if (xGrid) {
          Promise.all([
            xGrid.reloadColumn(columns),
            xGrid.reloadData(data)
          ]).then(() => {
            console.log(this.$refs.xGrid.getTableData())
            this.$XModal.message({
              content: `渲染成功,用时 ${Date.now() - startTime}毫秒`,
              status: 'info'
            })
            this.loading = false
          })
        }
      })
    },
    mockColumns (size) {
      return new Promise((resolve) => {
        const cols = [
          {
            width: 60,
            allowEmpty: false,
            type: 'seq',
            sortable: 'sortable',
            title: '#',
            field: '#',
            align: 'center'
          },
          {
            width: 100,
            allowEmpty: false,
            field: 'name',
            title: '姓名',
            align: 'center'
          },
          {
            width: 100,
            allowEmpty: false,
            field: 'sex',
            title: '性别',
            align: 'center'
          },
          {
            width: 100,
            allowEmpty: false,
            field: 'address',
            title: '地址',
            slots: { header: 'name_header' },
            align: 'center'
          },
          {
            width: 100,
            allowEmpty: false,
            field: 'phone',
            title: '电话',
            slots: {
              header: ({ column }) => {
                return [
                  <div class="slotBox">
                    <p class="titleBox1">{'@'}</p>
                    <p class="titleBox2">{column.title}</p>
                  </div>
                ]
              }
            },
            align: 'center'
          }
        ]
        resolve(cols)
      })
    },
    mockList (size) {
      return new Promise((resolve) => {
        const list = []
        for (let index = 0; index < 10; index++) {
          list.push({
            name: `名称${index}`,
            sex: 'man',
            address: '123',
            phone: '111111'
          })
        }
        resolve(list)
      })
    },
    getSelectEvent () {
      const selectRecords = this.$refs.xGrid.getCheckboxRecords()
      this.$XModal.alert(selectRecords.length)
    }
  },
  mounted () {
    // this.getData()
    // this.newGetData()
  }
}
</script>
<style>
.progress {
  height: 10px;
  background: #ebebeb;
  border-left: 1px solid transparent;
  border-right: 1px solid transparent;
  border-radius: 10px;
}
.progress > span {
  position: relative;
  float: left;
  margin: 0 -1px;
  min-width: 30px;
  height: 10px;
  line-height: 16px;
  text-align: right;
  background: #cccccc;
  border: 1px solid;
  border-color: #bfbfbf #b3b3b3 #9e9e9e;
  border-radius: 10px;
  background-image: -webkit-linear-gradient(
    top,
    #f0f0f0 0%,
    #dbdbdb 70%,
    #cccccc 100%
  );
  background-image: -moz-linear-gradient(
    top,
    #f0f0f0 0%,
    #dbdbdb 70%,
    #cccccc 100%
  );
  background-image: -o-linear-gradient(
    top,
    #f0f0f0 0%,
    #dbdbdb 70%,
    #cccccc 100%
  );
  background-image: linear-gradient(
    to bottom,
    #f0f0f0 0%,
    #dbdbdb 70%,
    #cccccc 100%
  );
  -webkit-box-shadow: inset 0 1px rgba(255, 255, 255, 0.3),
    0 1px 2px rgba(0, 0, 0, 0.2);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
}
.progress .orange {
  background: #fe8e01;
  border-color: #fe8e02 #fe8e02 #bf6b02;
  background-image: -webkit-linear-gradient(
    top,
    #feaa41 0%,
    #fe8e02 70%,
    #fe8e01 100%
  );
  background-image: -moz-linear-gradient(
    top,
    #feaa41 0%,
    #fe8e02 70%,
    #fe8e01 100%
  );
  background-image: -o-linear-gradient(
    top,
    #feaa41 0%,
    #fe8e02 70%,
    #fe8e01 100%
  );
  background-image: linear-gradient(
    to bottom,
    #feaa41 0%,
    #fe8e02 70%,
    #fe8e01 100%
  );
}
</style>

效果图
在这里插入图片描述




所属网站分类: 技术文章 > 博客

作者:听说你混的不错

链接:http://www.qianduanheidong.com/blog/article/237451/84fece1f76d1e92e1a2a/

来源:前端黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

8 0
收藏该文
已收藏

评论内容:(最多支持255个字符)