Ant Design Vue中table的使用

在Ant Design Vue中提供table组件供我们使用

 这是一个基础表格的组件,他的源代码是:

<template>
  <a-table :columns="columns" :data-source="data">
    <template #name="{ text }">
      <a>{{ text }}</a>
    </template>
    <template #customTitle>
      <span>
        <smile-outlined />
        Name
      </span>
    </template>
    <template #tags="{ text: tags }">
      <span>
        <a-tag
          v-for="tag in tags"
          :key="tag"
          :color="tag === 'loser' ? 'volcano' : tag.length > 5 ? 'geekblue' : 'green'"
        >
          {{ tag.toUpperCase() }}
        </a-tag>
      </span>
    </template>
    <template #action="{ record }">
      <span>
        <a>Invite 一 {{ record.name }}</a>
        <a-divider type="vertical" />
        <a>Delete</a>
        <a-divider type="vertical" />
        <a class="ant-dropdown-link">
          More actions
          <down-outlined />
        </a>
      </span>
    </template>
  </a-table>
</template>
<script lang="ts" setup>
import { SmileOutlined, DownOutlined } from '@ant-design/icons-vue';

const columns = [
  {
    dataIndex: 'name',
    key: 'name',
    slots: { title: 'customTitle', customRender: 'name' },
  },
  {
    title: 'Age',
    dataIndex: 'age',
    key: 'age',
  },
  {
    title: 'Address',
    dataIndex: 'address',
    key: 'address',
  },
  {
    title: 'Tags',
    key: 'tags',
    dataIndex: 'tags',
    slots: { customRender: 'tags' },
  },
  {
    title: 'Action',
    key: 'action',
    slots: { customRender: 'action' },
  },
];

const data = [
  {
    key: '1',
    name: 'John Brown',
    age: 32,
    address: 'New York No. 1 Lake Park',
    tags: ['nice', 'developer'],
  },
  {
    key: '2',
    name: 'Jim Green',
    age: 42,
    address: 'London No. 1 Lake Park',
    tags: ['loser'],
  },
  {
    key: '3',
    name: 'Joe Black',
    age: 32,
    address: 'Sidney No. 1 Lake Park',
    tags: ['cool', 'teacher'],
  },
];


</script>

在此代码中<a-table>标签中的:data-source是数据源,需要定义一个数据集合来作为数据源,

:colums是对列的定义,我们也需要定义一个对象的集合去配置列,类似代码中title表示此表格的列标题,dataindex表示数据的来源,需对应:data-source中的所需展示的数据的名称,除此之外,colums的配置还支持插槽,可以将我们所需的功能自己添加上去

      <template #action="{ record,index }" >
        <a-button type="primary" @click="handleActionminone(record,index)" style="margin-left: 8px">-1</a-button>
       <a-button type="primary" @click="handleActionminthree(record,index)" style="margin-left: 8px">-3</a-button>
       <a-button type="primary" @click="handleActionplusone(record,index)" style="margin-left: 8px; " :disabled="record.age>=100">+1</a-button>
       <a-button type="primary" @click="handleActionplusthree(record,index)" style="margin-left: 8px" :disabled="record.age>=97">+3</a-button>
       <a-button type="primary"  v-if="record.reform==false" style="margin-left: 8px" @click="handleActionreform(record,index)">关店整改</a-button>
       <a-button type="primary"  v-else danger style="margin-left: 8px" @click="handleActioncancel(record,index)">取消整改</a-button>
       <a-button  type="primary" @click="showModal(record,index)"  style="margin-left: 8px" > 删除此号</a-button>
      

    </template>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值