vue3+antd的table小组件

本文介绍了如何在Vue3项目中使用Ant Design的Table组件,重点在于如何配置搜索栏和添加操作按钮。通过示例代码展示具体的实现过程,帮助开发者了解组件的使用方法。
摘要由CSDN通过智能技术生成

antdtable组件支持增加搜索栏配置。增加按钮等操作。

闲话少叙,上代码

<!-- 更多与收起详见用户管理页面 -->
<template>
  <div class="c-data-table">
    <a-spin :spinning="spinning">
      <a-card :title="title" :bordered="false">
        <div class="dt-search" v-if="$slots.search || $slots.searchmore">
          <!--  -->
          <a-form
            ref="searchform"
            size="mini"
            class="dt-search-form-inline"
            layout="inline"
            :model="searchParams"
            @submit.prevent="search({ _fromBar: true, _begin: 0 })"
          >
            <div v-if="showmore">
              <div class="formSearchLittle">
                <slot name="search" />
              </div>
            </div>
            <div v-else>
              <div class="">
                <slot name="searchmore" />
              </div>
            </div>
            <button type="submit" style="display: none;"></button>
          </a-form>
        </div>
        <div class="dt-toolbar" v-if="$slots.toolbar">
          <slot name="toolbar" />
        </div>
        <a-table
          :columns="columns"
          :data-source="dataSource"
          :pagination="false"
          :bordered="bordered"
          rowKey="id"
        >
        </a-table>
        <a-config-provider :locale="locale" v-if="pageable">
          <a-pagination
            show-size-changer
            v-model:current="current"
            v-model:pageSize="pageSize"
            :total="total"
            :showQuickJumper="true"
            @showSizeChange="onShowSizeChange"
            @change="onChange"
          >
          </a-pagination>
        </a-config-provider>
      </a-card>
    </a-spin>
  </div>
</template>
<script>
import {
    defineComponent, ref, watch, getCurrentInstance } from "vue";
import zhCN from "ant-design-vue/lib/locale-provider/zh_CN";
import {
    message } from "ant-design-vue";
import {
    useForm } from "@ant-design-vue/use";
export default defineComponent({
   
  name: "c-data-table",
  props: {
   
    //是否显示边框
    bordered: {
   
      type: Boolean,
      default: false,
    },
    // 请求的返回渲染参数
    resultKey: {
   
      type: String,
      default: "data",
    },
    // 行
    columns: Array,
    //请求地址
    serverId: String,
    //搜索请求
    searchParams: {
   
      type: Object,
      default: () => ({
   }),
    },
    title: String,
    // 是否显示分页
    pageable: {
   
      type: Boolean,
      default: true,
    },
  },
  setup() {
   
    let {
    proxy } = getCurrentInstance();
    const dataSource = ref([]);
    // const searchParams = reactive({ name: "" });
    const {
    resetFields } = useForm(proxy.$props.searchParams, {
   });
    const spinning = ref(false);
    const pageSize = ref(20);
    const current = ref(1);
    const total = ref(0);
    const onShowSizeChange = (current, pageSize) => {
   
      console.log(current, pageSize);
    };
    const onChange = (pageNumber) => {
   
      console.log("Page: ", pageNumber);
      search();
    };

    // 页面搜索
    const search = (params = {
   }, fn = (rows) => rows) => {
   
      const {
    _begin } = params;
      console.log(proxy, fn);
      if (_begin >
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lbchenxy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值