mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-07 23:55:07 +08:00
feat: 封装xTable 组件
This commit is contained in:
28
yudao-ui-admin-vue3/src/hooks/web/useXTable.ts
Normal file
28
yudao-ui-admin-vue3/src/hooks/web/useXTable.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { ref, unref } from 'vue'
|
||||
import { XTableProps } from '@/components/XTable/src/type'
|
||||
|
||||
export interface tableMethod {
|
||||
reload: () => void
|
||||
setProps: (props: XTableProps) => void
|
||||
}
|
||||
|
||||
export function useXTable(props: XTableProps): [Function, tableMethod] {
|
||||
const tableRef = ref<Nullable<tableMethod>>(null)
|
||||
|
||||
function register(instance) {
|
||||
tableRef.value = instance
|
||||
props && instance.setProps(props)
|
||||
}
|
||||
function getInstance(): tableMethod {
|
||||
const table = unref(tableRef)
|
||||
if (!table) {
|
||||
console.error('表格实例不存在')
|
||||
}
|
||||
return table as tableMethod
|
||||
}
|
||||
const methods: tableMethod = {
|
||||
reload: () => getInstance().reload(),
|
||||
setProps: (props) => getInstance().setProps(props)
|
||||
}
|
||||
return [register, methods]
|
||||
}
|
Reference in New Issue
Block a user