云存储 负责管理 Telegram 迷你应用程序中云存储的💠组件。 检查支持要检查当前 Telegram 迷你应用程序版本是否支持云存储,需要使用 isSupported 方法: Variable : - import { cloudStorage } from '@telegram-apps/sdk';
" I' b' O$ K6 {" U! j) k, n
# a$ w6 N% f* \) A V0 g+ F8 d- cloudStorage.isSupported(); // boolean
复制代码 6 `5 ?9 ^6 B9 R3 \' p3 j; G( @# j
Functions : - import { isCloudStorageSupported } from '@telegram-apps/sdk';- i" ~; j/ q6 x
: t, M7 t8 q3 M- isCloudStorageSupported(); // boolean
复制代码 设置项目要设置键值,请使用 setItem 方法。 Variable : - await cloudStorage.setItem('a', 'a-value');
复制代码Functions : - import { setCloudStorageItem } from '@telegram-apps/sdk';
* }" Y' S7 A3 p
, i. {0 ?) d5 s8 j1 k- await setCloudStorageItem('a', 'a-value');
复制代码 获取钥匙要获取所有现有密钥的列表,请使用 getKeys 方法。 Variable : - const keys = await cloudStorage.getKeys(); // ['a', 'b', 'c']
复制代码Functions : - import { getCloudStorageKeys } from '@telegram-apps/sdk'; D |0 U9 x5 Y
- : m- Q) P6 F/ o, g8 J @
- const keys = await getCloudStorageKeys(); // ['a', 'b', 'c']
复制代码
+ B5 U; f& w+ R+ B B要获取特定键或多个键的值,请使用 getItem 方法。 Variable : - const nonExistent = await cloudStorage.getItem('non-existent');
' F2 P2 E+ T2 b/ w3 a7 G - // The result is an empty string: ''
' A) X0 G# X8 q: b
* i7 t1 M4 |( t3 t$ i: r6 C) D- const existent = await cloudStorage.getItem('a');
+ q5 T8 c+ ?1 y! D x/ p: }5 |$ i: `, X - // The result is the value of the 'a' key. Example: 'a-value'
* v) P b/ n9 S7 _5 s - / L0 T/ ~$ B3 e0 I6 \7 C* ^
- const values = await cloudStorage.getItem(['a', 'b', 'non-existent']);
7 W' f, {8 |. u& Z& K9 g t2 H/ Q( _ - // The result is a record of the keys 'a', 'b', and 'non-existent'.
$ A0 d4 K) t3 Q$ N% r: G - // Example:
3 J) N: c" t/ V0 ?- d - // {
/ R5 q# v) v5 F - // a: 'a-value', * K7 k. B; Z ` j4 k: `8 I
- // b: 'b-value', , [' }- [: A! I
- // 'non-existent': '',
`! J9 U2 z4 J4 ]% p* f/ S - // }
复制代码Functions : - import { getCloudStorageItem } from '@telegram-apps/sdk'; N) P7 Q* r# Q- [0 r& \% V
9 h/ c B. O: M5 A- R8 I- const nonExistent = await getCloudStorageItem('non-existent');
) y( |1 ], d' m4 ~& b$ i - // The result is an empty string: ''
* R' q6 p" w P$ o+ g; w
/ @6 W' U- ]6 l( v- const existent = await getCloudStorageItem('a');
1 }3 h/ E: n) S" C - // The result is the value of the 'a' key. Example: 'a-value'+ D! f/ h+ ]# i
- 5 `6 P, _, M% H# E P
- const values = await getCloudStorageItem(['a', 'b', 'non-existent']);8 b4 d1 ^ N6 D) @3 N; P; K
- // The result is a record of the keys 'a', 'b', and 'non-existent'. 8 `4 {1 n7 ^8 R
- // Example:
+ Z1 z g+ Y6 B - // { 4 h9 E$ x2 x1 {7 X
- // a: 'a-value',
( F% R5 N- H$ [ - // b: 'b-value',
8 J/ u# e+ R9 w" ~3 Z7 w% z0 K7 M - // 'non-existent': '', 3 [' C1 s7 K0 b. k- M
- // }
复制代码 删除项目要删除一个键或键列表,请使用 deleteItem 方法。 Variable : - await cloudStorage.deleteItem('a');8 w; p5 J7 S* M% T) v
- await cloudStorage.deleteItem(['a', 'b', 'c']);
复制代码Functions : - import { deleteCloudStorageItem } from '@telegram-apps/sdk'; E5 s- z; @& `$ R" I: b
$ A. }" @/ F! t- await deleteCloudStorageItem('a');8 ~: e3 u& P6 M- k( o9 ~
- await deleteCloudStorageItem(['a', 'b', 'c']);
复制代码
6 C& [0 @$ n { l# _) R8 y" H- E/ F. e" J2 J0 t# Y
|