简体   繁体   English

vue ant 设计如何创建带槽的可重用表组件

[英]vue ant design how to create reusable table component with slots

I try to create reusable table component with Ant Design Vue and use it throught the project.我尝试使用 Ant Design Vue 创建可重用的表组件,并在整个项目中使用它。 Sometimes I need show custom columns with icons an so on, so I want send them in this case like a slots.有时我需要显示带有图标的自定义列等等,所以我想在这种情况下像插槽一样发送它们。

I have my table component ATable我有我的表格组件 ATable

 <template>
  <a-table
    :columns="scheme"
    :data-source="props.data"
    :loading="isLoading"
    :pagination="pagination"
    :row-key="(record:any) => record.name"
    @change="handleTableChange"
    :scroll="{ x: 1100 }">
<template v-slot:bodyCell="{ column, record }">
  <template v-for="(_, name) in $slots" :key="name">
    <slot v-bind="{ column, record }" :name="name"></slot>
  </template>
</template>

And component where I insert this table以及我插入此表的组件

  <ATable
    :data="dataList"
    :loading="isLoading"
    :scheme="scheme"
    :pagination="pagination"
    @set-query="setQuery" >
      <template v-if="column.key === 'test'">
        <a
          class="hover:underline"
          :href="record.test.path"
          target="_blank">
          {{ record.environment.name }}
        </a>
  </template>
 </ATable>

My question is how I should paste my special rows in ATable if I don`t have access to column and record here (cause it is inside ATable bodyCell)?我的问题是,如果我无法在此处访问列和记录(因为它在 ATable bodyCell 内),我应该如何将我的特殊行粘贴到 ATable 中?

   <ATable
:data="dataList"
:loading="isLoading"
:scheme="scheme"
:pagination="pagination"
@set-query="setQuery" >
<template #test="{ column, record }">
  <div v-if="column.key === 'environment'" class="text-caption">
    <a
      class="hover:underline"
      :href="record.environment.path"
      target="_blank">
      {{ record.test.name }}
    </a>
  </div>
</template>
</ATable>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM