提交 | 用户 | age
|
116a1f
|
1 |
import type { Ref } from 'vue'; |
V |
2 |
import type { BasicTableProps, TableActionType } from '../types/table'; |
|
3 |
import { provide, inject, ComputedRef } from 'vue'; |
|
4 |
|
|
5 |
const key = Symbol('basic-table'); |
|
6 |
|
|
7 |
type Instance = TableActionType & { |
|
8 |
wrapRef: Ref<Nullable<HTMLElement>>; |
|
9 |
getBindValues: ComputedRef<Recordable>; |
|
10 |
}; |
|
11 |
|
|
12 |
type RetInstance = Omit<Instance, 'getBindValues'> & { |
|
13 |
getBindValues: ComputedRef<BasicTableProps>; |
|
14 |
}; |
|
15 |
|
|
16 |
export function createTableContext(instance: Instance) { |
|
17 |
provide(key, instance); |
|
18 |
} |
|
19 |
|
|
20 |
export function useTableContext(): RetInstance { |
|
21 |
return inject(key) as RetInstance; |
|
22 |
} |