这个是缩减之后的代码,使用vite运行,提示的错误是:Cannot read properties of undefined (reading 'type')vue,如果把 “#[key]="{ row, rowIndex, column }"“ 删掉就没有问题了。
<template>
<div class="n_table">
<div class="table_content"><template v-for="item in columns" :key="item.dataIndex"><template
v-for="(value, key) in $slots" :key="key"><template v-if="item.dataIndex === key"
#[key]="{ row, rowIndex, column }">
<slot :name="key" :row="row" :rowIndex="rowIndex" :column="column"></slot>
</template>
</template>
</template>
</div>
</div>
</template>
<script setup>
import { ref, useSlots } from 'vue';
const props = defineProps({
// 表格列配置
columns: {
type: Array,
default: () => [],
},
})
const slots = ref({});
slots.value = useSlots()
</script>