在公司开发大型项目中,使用主流表格库 vxe-table 和 element-ui 组件库,可以在可编辑单元格中渲染非常简单的使用更多的组件
安装
npm install vxe-pc-ui@3.3.9 vxe-table@3.11.10 @vxe-ui/plugin-render-element@3.0.0
// ...
import { VxeUI } from 'vxe-table'
import VxeUIPluginRenderElement from '@vxe-ui/plugin-render-element'
import '@vxe-ui/plugin-render-element/dist/style.css'
// ...
VxeUI.use(VxeUIPluginRenderElement)
使用输入框 el-input
<template>
<div>
<vxe-grid ref="gridRef" v-bind="gridOptions"></vxe-grid>
</div>
</template>
<script>
export default {
data () {
const gridOptions = {
border: true,
showOverflow: true,
keepSource: true,
editConfig: {
trigger: 'click',
mode: 'row'
},
columns: [
{ type: 'checkbox', width: 60 },
{ type: 'seq', title: 'Number', width: 80 },
{ field: 'name', title: 'Name', minWidth: 140, editRender: { name: 'ElInput' } },
{ field: 'nickname', title: '输入框', width: 200, editRender: { name: 'ElInput' } }
],
data: [
{ id: 10001, name: 'Test1', nickname: 'Nickname11' },
{ id: 10002, name: 'Test2', nickname: '' }
]
}
return {
gridOptions
}
}
}
</script>
使用下拉框 el-select
<template>
<div>
<vxe-grid ref="gridRef" v-bind="gridOptions"></vxe-grid>
</div>
</template>
<script>
export default {
data () {
const sexEditRender = {
name: 'ElSelect',
options: [
{ label: '男', value: '1' },
{ label: '女', value: '0' }
]
}
const sexListEditRender = {
name: 'ElSelect',
props: {
multiple: true
},
options: [
{ label: '男', value: '1' },
{ label: '女', value: '0' }
]
}
const gridOptions = {
border: true,
showOverflow: true,
keepSource: true,
editConfig: {
trigger: 'click',
mode: 'row'
},
columns: [
{ type: 'checkbox', width: 60 },
{ type: 'seq', title: 'Number', width: 80 },
{ field: 'name', title: 'Name', minWidth: 140, editRender: { name: 'ElInput' } },
{ field: 'sex', title: '下拉框', width: 200, editRender: sexEditRender },
{ field: 'sexList', title: '下拉框多选', width: 200, editRender: sexListEditRender }
],
data: [
{ id: 10001, name: 'Test1', sex: '1', sexList: [] },
{ id: 10002, name: 'Test2', sex: '', sexList: ['0', '1'] }
]
}
return {
gridOptions
}
}
}
</script>
使用日期选择 el-date-picker
<template>
<div>
<vxe-grid ref="gridRef" v-bind="gridOptions"></vxe-grid>
</div>
</template>
<script>
export default {
data () {
const gridOptions = {
border: true,
showOverflow: true,
keepSource: true,
editConfig: {
trigger: 'click',
mode: 'row'
},
columns: [
{ type: 'checkbox', width: 60 },
{ type: 'seq', title: 'Number', width: 80 },
{ field: 'name', title: 'Name', minWidth: 140, editRender: { name: 'ElInput' } },
{ field: 'date1', title: '日期', width: 200, editRender: { name: 'ElDatePicker', props: { type: 'date', valueFormat: 'yyyy-MM-dd' } } },
{ field: 'date2', title: '日期带时间', width: 220, editRender: { name: 'ElDatePicker', props: { type: 'datetime', valueFormat: 'yyyy-MM-dd HH:mm:ss' } } }
],
data: [
{ id: 10001, name: 'Test1', date1: '', date2: '' },
{ id: 10002, name: 'Test2', date1: '2018-01-01', date2: '2018-01-01 10:10:30' }
]
}
return {
gridOptions
}
}
}
</script>
使用级联选择 el-cascader
<template>
<div>
<vxe-grid ref="gridRef" v-bind="gridOptions"></vxe-grid>
</div>
</template>
<script>
export default {
data () {
const regionList = [
{
label: '北京',
value: 1,
children: [
{ value: 3, label: '东城区' },
{ value: 4, label: '西城区' }
]
},
{
label: '上海',
value: 21,
children: [
{ value: 23, label: '黄浦区' },
{ value: 24, label: '卢湾区' }
]
},
{
label: '广东',
value: 42,
children: [
{ value: 43, label: '广州市' },
{ value: 67, label: '深圳市' }
]
}
]
const regionEditRender = {
name: 'ElCascader',
props: {
options: regionList
}
}
const gridOptions = {
border: true,
showOverflow: true,
keepSource: true,
editConfig: {
trigger: 'click',
mode: 'row'
},
columns: [
{ type: 'checkbox', width: 60 },
{ type: 'seq', title: 'Number', width: 80 },
{ field: 'name', title: 'Name', minWidth: 140, editRender: { name: 'ElInput' } },
{ field: 'region', title: '级联选择', width: 200, editRender: regionEditRender }
],
data: [
{ id: 10001, name: 'Test1', region: [] },
{ id: 10002, name: 'Test2', region: [21, 24] }
]
}
return {
gridOptions,
regionList,
regionEditRender
}
}
}
</script>
还有非常的多,具体需要去看官网文档了
https://gitee.com/xuliangzhan/vxe-table
标签:name,title,vxe,value,element,width,ui,label,true From: https://www.cnblogs.com/qaz666/p/18574108