Skip to content

CommonQueryTable Query Table

A highly integrated query page component that includes form queries, table display, and pagination.

Basic Usage

Username
Status
Please select status

暂无数据

展开代码
复制代码

Slot Layout

The component provides 6 layout slots, control the page layout through slot content:

  • header - Header area
  • form - Form query area
  • toolbar - Toolbar area
  • table - Table area (default display)
  • pagination - Pagination area
  • footer - Footer area

Slot Display Rules

  • header, toolbar, footer: Displayed only when slot content is provided
  • form: Displayed when slot content is provided or form configuration exists
  • table: Always displayed by default
  • pagination: Displayed when slot content is provided or has data (total > 0)

Table with Pagination

Display only table and pagination without form prop.

暂无数据

展开代码
复制代码

Toolbar

Add operation buttons via toolbar slot.

Username
Status
Please select status

暂无数据

展开代码
复制代码

Display additional information via footer slot.

Username
Status
Please select status

暂无数据

展开代码
复制代码

Pagination Configuration

CommonQueryTable has built-in complete pagination functionality, supporting custom pagination parameters and styles.

Pagination Notes

  • Global default page number and page size can be set via CommonConfigProvider component
  • Pagination component will automatically display when the returned total from the API is greater than the page size
  • Pagination parameters pageNo and pageSize are automatically passed to the fetch function
用户名
状态
请选择状态

暂无数据

展开代码
复制代码

Pagination Props

Customize pagination component behavior via pagination-* prefixed attributes:

AttributeDescriptionTypeDefault
pagination-page-sizeArray of page size optionsnumber[][10, 20, 50, 100]
pagination-default-page-sizeDefault page sizenumber10
pagination-layoutPagination component layoutstring'total, sizes, prev, pager, next, jumper'
pagination-backgroundWhether to show background colorbooleantrue
pagination-page-countTotal page count (usually calculated from total)number-

Pagination Events

EventDescriptionCallback Parameters
@pagination-changeTriggered when pagination changes{ pageNo: number, pageSize: number }

Slot Pass-through

In actual use, you may need to use slot functionality on the form or table components under CommonQueryTable.

Slot Naming Rule

Pass slots to internal components via componentName-slotName:

  • form-name - Pass name slot to form component
  • table-status - Pass status slot to table component
  • table-empty - Pass empty state slot to table component (corresponds to Element Plus el-table's #empty)
Username
You can define custom components here
Status
Please select status

暂无数据

展开代码
复制代码

Attribute Pass-through

Although the component provides some default attributes, it cannot meet all requirements. Supports passing additional attributes and events to internal components via attribute pass-through.

Pass-through Rule

  • Attribute Pass-through: Pass attributes to internal components via componentName-attributeName
  • Event Pass-through: Listen to internal component events via @componentName-eventName

Attribute Pass-through Example

Pass additional attributes to internal components, for example, setting form to non-inline mode:

vue
<CommonQueryTable
  :form-inline="false"
  ...
/>

Event Pass-through Example

Listen to internal component events, for example, listening to table selection changes:

vue
<script setup>
function handleSelectionChange(selection) {
  console.log('Selected items:', selection)
}
</script>

<template>
  <CommonQueryTable
    @table-selection-change="handleSelectionChange"
    ...
  />
</template>

The following complete example shows the actual usage of attribute pass-through and event pass-through:

Username
Status
Please select status

暂无数据

展开代码
复制代码

API

Props

ParameterDescriptionTypeDefault
fetchData fetch function, receives query parameters and returns a Promise containing list and total(params?: ListParam) => Promise<{ list: T[]; total: string | number }>Required
formForm configuration array, defines fields and properties of query formCommonFormItemArray<T>[]
columnsTable column configuration, defines table column structure and displayCommonTableColumn<T>Required
pagination-*Pagination component attribute pass-through, see Pagination Configuration section--

Slots

Layout Slots

CommonQueryTable supports passing content to internal components via layout slots:

NameDescriptionTarget
headerHeader area slotPage header
formForm area slotQuery form component
toolbarToolbar slotTable toolbar
tableTable area slotData table component
paginationPagination area slotPagination component
footerFooter area slotPage footer

Sub-component Slot Passing

Pass slots to internal components via prefix:

  • form-* - Pass slots to internal CommonForm component
  • table-* - Pass slots to internal CommonTable component
  • pagination-* - Pass slots to internal CommonPagination component

Usage Example:

  • form-name - Pass name slot to form component
  • table-status - Pass status slot to table component
  • pagination-sizes - Pass sizes slot to pagination component

Exposes

The component exposes the following methods that can be called via ref:

MethodDescriptionParametersReturn Value
refreshRefresh list data-void
resetReset query conditions and pagination-void
getFormDataGet current form data-Partial<T>
getSelectionRowsGet selected row data from table-T[]

TypeScript Types

The component exports the following TypeScript type definitions for direct use in your project:

CommonQueryTableProps

typescript
interface CommonQueryTableProps<T extends AnyObject = AnyObject> {
  /** Data fetch function */
  fetch: (params?: ListParam) => Promise<{ list: T[]; total: string | number }>

  /** Form configuration array */
  form?: CommonFormItemArray<T>

  /** Table column configuration */
  columns: CommonTableColumn<T>
}

CommonQueryTableExpose

Type definition for component instance, used for ref type annotation:

typescript
interface CommonQueryTableExpose<T = AnyObject> {
  /** Refresh list data */
  refresh: () => void

  /** Reset query conditions and pagination */
  reset: () => void

  /** Get form data */
  getFormData: () => Partial<T>

  /** Get selected row data from table */
  getSelectionRows: () => T[]
}

ListParam

typescript
/**
 * List request parameter type
 * @typeParam T - Additional query parameter type
 */
type ListParam<T extends AnyObject = AnyObject> = PaginationParam & T

/**
 * Pagination request parameters
 */
type PaginationParam = {
  pageNo: number
  pageSize: number
}

Usage Example:

typescript
import type {
  CommonQueryTableProps,
  ListParam,
} from '@yetuzi/vue3-query-components'

// Define query parameter type
interface MyQueryParams {
  name: string
  status: number
}

// Define data row type
interface UserData {
  id: number
  name: string
  email: string
}

// Use types
const fetch = (params: ListParam<MyQueryParams>) => {
  // params includes: pageNo, pageSize, name, status
  return Promise.resolve({
    list: [] as UserData[],
    total: 0
  })
}

MIT Licensed