发布于2021-11-20 16:40 阅读(1570) 评论(0) 点赞(8) 收藏(1)
文档官网:https://xuliangzhan_admin.gitee.io/vxe-table/#/table/start/install
在列头上,有时候显示的title信息并不能满足我们想要显示的内容,这个时候查看文档,发现了自定义模块,使用插槽可以帮助我们实现自定义模板内容
在插槽内容可以自定义模板,用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/
来源:前端黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 前端黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-3
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!