1.子组件table
<a-table :pagination="false"//关闭自身带的分页 :dataSource="dataSource"//表格数据 :columns="columns"//表头 :row-selection="{//前面的选择框 selectedRowKeys: selectedRowKeys, onChange: onSelectChange, }" >
//插槽 <template v-slot:[item]="scope" v-for="item in renderArr"> <slot :name="item" :scope="scope" v-bind="scope || {}"></slot> </template> </a-table>
然后引入useSlots
import { reactive, useSlots } from "vue";
setup(props, { emit }) { const slots = useSlots(); const renderArr = Object.keys(slots); const data = reactive({ renderArr, }) return { ...toRefs(data), }; }
1.父组件掉用子组件table
<Wtable :dataSource="dataSource" :columns="columns" :isShowSelect="isShowSelect" > <template #Action="{ record }"> <span>
<a class="mrg" @click="del(record)">删除</a>
</span>
</template>
</Wtable>
import { ref, createVNode } from "vue";
import { Modal } from "ant-design-vue";
import { ExclamationCircleOutlined } from "@ant-design/icons-vue";
import Wtable from "../../components/Wtable/index.vue";
const del = (val) => {
Modal.confirm({
title: () => "您确定要删除吗?",
icon: () => createVNode(ExclamationCircleOutlined),
content: () => "该操作不可逆!",
okText: () => "确定删除",
okType: "danger",
cancelText: () => "再想想",
onOk() {
console.log("OK");
},
onCancel() {
console.log("Cancel");
},
});
}