useView
- Category:
Composables - Relate:
getTablegetViewById - 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 { useView, useSelection } from "@qww0302/use-bitable"
import { ref, watch } from "vue"
const { tableId, viewId } = useSelection()
const { view } = useView(tableId, viewId)
const name = ref()
const type = ref()
const meta = ref()
watch(
() => view.value,
(v) => {
name.value = "Loading..."
type.value = "Loading..."
meta.value = "Loading..."
if (v) {
Promise.all([
v.getName().then((res) => (name.value = res)),
v.getType().then((res) => (type.value = res)),
v.getMeta().then((res) => (meta.value = res)),
])
}
}
)
</script>
<template>
<div class="tip custom-block">
<p class="custom-block-title">
TIP
</p>
<p>Choose different view</p>
</div>
<div>
Current View:
<ul>
<li>viewId: {{ view?.id }}</li>
<li>tableId: {{ view?.tableId }}</li>
<li>type: {{ type }}</li>
<li>
meta:
<pre>{{ JSON.stringify(meta, null, 2) }}</pre>
</li>
</ul>
</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
36
37
38
39
40
41
42
43
44
45
46
47
48
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
36
37
38
39
40
41
42
43
44
45
46
47
48
Usage
useView returns a reactive IView object, which changes in real time according to the incoming parameters.
TIP
This function is based on getViewById implementation, because the official API are asynchronous functions, so the update of view will have a certain delay. Therefore, this function provides pending to reflect the acquisition status, which is true when the view is being acquired.
ts
import { useView } from "@qww0302/use-bitable"
import { ref } from "vue"
const tableId = ref<string | null>(null)
const viewId = ref<string | null>(null)
const { view, pending } = useView(tableId, viewId)1
2
3
4
5
6
7
2
3
4
5
6
7
Type Declarations
ts
import { MaybeRefOrGetter } from "vue"
import type { ITable, IView } from "@lark-base-open/js-sdk"
export declare function useView(
table: MaybeRefOrGetter<ITable | string | null>,
viewId: MaybeRefOrGetter<string | null>,
): {
view: import("vue").ShallowRef<IView | null, IView | null>
pending: import("vue").Ref<boolean, boolean>
}1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9