fix: update bodyCell headerCell

pull/4639/head
tangjinzhou 2021-09-06 19:27:41 +08:00
parent 562d86f189
commit c45b93bc8e
3 changed files with 9 additions and 3 deletions

View File

@ -623,7 +623,6 @@ const Table = defineComponent<TableProps>({
setup(_props, { attrs, slots }) { setup(_props, { attrs, slots }) {
return () => { return () => {
const columns = (attrs.columns || convertChildrenToColumns(slots.default?.())) as ColumnsType; const columns = (attrs.columns || convertChildrenToColumns(slots.default?.())) as ColumnsType;
console.log('slots', slots);
return ( return (
<InteralTable <InteralTable
{...attrs} {...attrs}

View File

@ -1,3 +1,4 @@
import devWarning from '../../vc-util/devWarning';
import type { Ref } from 'vue'; import type { Ref } from 'vue';
import { ContextSlots } from '../context'; import { ContextSlots } from '../context';
import type { TransformColumns, ColumnTitleProps, ColumnsType } from '../interface'; import type { TransformColumns, ColumnTitleProps, ColumnsType } from '../interface';
@ -13,6 +14,12 @@ function fillTitle<RecordType>(
const cloneColumn = { ...column }; const cloneColumn = { ...column };
const { slots = {} } = cloneColumn; const { slots = {} } = cloneColumn;
devWarning(
!('slots' in cloneColumn),
'Table',
'`column.slots` is deprecated. Please use `v-slot:headerCell` `v-slot:bodyCell` instead.',
);
Object.keys(slots).forEach(key => { Object.keys(slots).forEach(key => {
const name = slots[key]; const name = slots[key];
if (cloneColumn[key] === undefined && $slots[name]) { if (cloneColumn[key] === undefined && $slots[name]) {

View File

@ -119,7 +119,7 @@ export default defineComponent<CellProps>({
const children = slots.default?.(); const children = slots.default?.();
if (validateValue(children) || cellType === 'header') { if (validateValue(children) || cellType === 'header') {
childNode = children; childNode = children;
if (cellType === 'header' && contextSlots.value.headerCell) { if (cellType === 'header' && contextSlots.value.headerCell && !column.slots?.title) {
childNode = contextSlots.value.headerCell({ title: column.title, index, column }); childNode = contextSlots.value.headerCell({ title: column.title, index, column });
} }
} else { } else {
@ -138,7 +138,7 @@ export default defineComponent<CellProps>({
} }
} }
if (cellType === 'body' && contextSlots.value.bodyCell) { if (cellType === 'body' && contextSlots.value.bodyCell && !column.slots?.customRender) {
childNode = contextSlots.value.bodyCell({ text: value, value, record, index, column }); childNode = contextSlots.value.bodyCell({ text: value, value, record, index, column });
} }
} }