useTable
- Category:
Composables - Relate:
getTable - Dependencies:
@lark-base-open/js-sdk - Last Changed: last week
Notice
This function needs to use in Base, please use this website as a plugin in a Base to see the demo.
Demo
Show demo code
vue
<script setup lang="ts">
import { useTable, useSelection } from "@qww0302/use-bitable"
import { ref, watch } from "vue"
const { tableId } = useSelection()
const { table, pending } = useTable(tableId)
const name = ref()
watch(
() => table.value,
(t) => {
name.value = null
if (t) {
t.getName().then(res => {
name.value = res
})
}
}
)
</script>
<template>
<div class="tip custom-block">
<p class="custom-block-title">
TIP
</p>
<p>Choose different table</p>
</div>
<div>
Table name:
<span v-if="!pending && name">{{ name ?? "null" }}</span>
<span v-else-if="pending || !name">loading table...</span>
</div>
</template>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Usage
useTable returns a responsive ITable object, which changes in real time according to the parameters passed in. The passed-in value can be the id or name of the table.
TIP
This function is based on getTable, since the official API are all async functions, the update of table will be delayed. Therefore, this function provides pending to reflect the acquisition status, which is true when the table is being acquired.
ts
import {useTable} from "@qww0302/use-bitable"
import { ref } from "vue"
const tableId = ref<string | null>(null)
const { table, pending } = useTable(tableId)1
2
3
4
5
6
2
3
4
5
6
Type Declarations
ts
import { MaybeRefOrGetter } from "vue"
import { ITable } from "@lark-base-open/js-sdk"
/**
* Reactive table
*
* 响应式表格
*
* @param tableIdOrName
* @returns
*/
export declare function useTable(
tableIdOrName: MaybeRefOrGetter<string | null>,
): {
table: import("vue").ShallowRef<ITable | null, ITable | null>
pending: import("vue").Ref<boolean, boolean>
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16