设置按钮 负责 Telegram Mini Apps settings button 的💠组件。 检查支持要检查当前 Telegram 迷你应用程序版本是否支持设置按钮,可使用 isSupported 方法: Variable : - import { settingsButton } from '@telegram-apps/sdk';
E- u5 h/ ?9 R0 l7 a+ Q
: Q1 e6 @+ H9 x* b( t- settingsButton.isSupported(); // boolean
复制代码Functions : - import { isSettingsButtonSupported } from '@telegram-apps/sdk';1 ^' i& P$ }( d+ W" i
- 8 l5 P# }9 `7 c C2 `1 F( e+ F% c
- isSettingsButtonSupported(); // boolean
复制代码 安装在使用该组件之前,有必要将其安装到正确配置的属性中。 为此,请使用 mount 方法。 它将更新 isMounted 信号属性。 Variable : - import { settingsButton } from '@telegram-apps/sdk';+ L# L A- R- o3 \$ F, d
( j* H z4 c) o. B' Y- settingsButton.mount(); o7 Z, B7 `' q/ q9 i/ U
- settingsButton.isMounted(); // true
复制代码Functions : - import {
( z$ h" J3 F# _) e5 j - mountSettingsButton,
# w& j- o$ t% P! N: e' H, a - isSettingsButtonMounted,
% o! A; K% t9 c2 y# _0 N; T - } from '@telegram-apps/sdk';0 A/ P* T8 z6 L# |1 J6 R
- + |; X% @( E4 ^4 N$ s
- mountSettingsButton();, c [. p. a. w- D
- isSettingsButtonMounted(); // true
复制代码 2 ^& c0 K9 F) E8 x
要卸载,请使用 unmount 方法: Variable : - settingsButton.unmount();' h% {* V4 o3 E
- settingsButton.isMounted(); // false
复制代码Functions : - import {
5 E" Z" A2 r. J+ i1 `' j& g - unmountSettingsButton,0 B7 C2 p9 U' ^4 o0 f+ H
- isSettingsButtonMounted,5 n% {! V$ a# x, y* y/ G4 c
- } from '@telegram-apps/sdk';
8 ]2 ]1 e+ h( t+ x - 0 a$ a/ N8 [2 o9 _4 s
- unmountSettingsButton();) B& _0 e/ z; C3 P0 d$ l0 N. I
- isSettingsButtonMounted(); // false
复制代码 展示与隐藏要更改按钮的可见性,请使用 hide() 和 show() 方法。 这些方法会更新 isVisible 信号属性值。 Variable : - settingsButton.show();& N- i/ X% J3 [) f! v& J! n* F
- settingsButton.isVisible(); // true5 X4 Z( \$ M* `1 k( Y2 J' }! Z, {
- & Z; j O, k z8 w9 G- b3 g
- settingsButton.hide();
- [# h: A7 N* ]8 S/ E - settingsButton.isVisible(); // false
复制代码Functions : - import {
( `. H. }) c+ T3 Z( P3 d+ | - showSettingsButton,$ a# r' K) t/ i, S
- hideSettingsButton,- `/ p$ ^# J) O, |0 n/ Z1 a* M
- isSettingsButtonVisible,* A8 `3 E* ?5 @" C- f: @9 T
- } from '@telegram-apps/sdk';' V7 Z$ Y# @& g1 `" n) I
! f+ p, d- h: ]$ `: D5 z- showSettingsButton();
# B$ U3 R8 m6 R- ^' m4 C5 w. ~ - isSettingsButtonVisible(); // true- I7 J& _% }" |* ~9 _# Z
: W4 a: L, a( J: f- hideSettingsButton();
, b1 M* V$ ~, q Q Y1 C# _) H0 L - isSettingsButtonVisible(); // false
复制代码 跟踪点击要添加按钮点击监听器,请使用 onClick 方法。 它返回一个函数,用于移除绑定的 监听器。 或者,您也可以使用 offClick 方法。 Variable : - function listener() {2 e& ^% n' i" t* A3 h& d6 l
- console.log('Clicked!');
) {! n5 @' y, v - }
' [, X+ E) N( Z C" t. ? - & [! M; n: O% [% V5 }- `
- const offClick = settingsButton.onClick(listener);- U7 `0 k1 G A- Z# n
- offClick();
( b D! W" h J: Q - // or
. b: _, y4 k# v9 {6 n/ o - settingsButton.onClick(listener);, `& n1 ^7 O- }2 ^8 U3 C. }/ A" W
- settingsButton.offClick(listener);
复制代码Functions : - import { onSettingsButtonClick, offSettingsButtonClick } from '@telegram-apps/sdk';7 B% |4 s! H, W( p5 ]
- 7 L1 n# v6 b" `0 O6 p9 ^
- function listener() {
5 q: ~; Z7 N( m5 E - console.log('Clicked!');
, u) c' n, {9 B6 ~* C8 x - }6 |# c, \8 n; x& O' A7 p* C
- & N2 a3 P7 i; ~4 J" m% k
- const offClick = onSettingsButtonClick(listener);7 G. A% G m8 d( i7 ^, M) |* z
- offClick();
, t0 b1 r& A# J! P" o& o/ F - // or0 U: x2 O3 ?# \" Y/ u8 b
- onSettingsButtonClick(listener);
( [- Q" i& R' r) B' v$ E - offSettingsButtonClick(listener);
复制代码 9 e% s! ] K' X- A/ p
0 ^$ f/ p+ Q- S4 q# h0 V, O5 o |