辅助按钮 负责 Telegram 迷你应用程序二级按钮的💠组件。 检查支持要检查当前 Telegram 迷你应用程序版本是否支持辅助按钮,请使用 isSupported 方法: Variable : - import { secondaryButton } from '@telegram-apps/sdk';
) u6 t" e& ~" i, B8 z( S) T" L( s
5 ~3 f; E5 M% }5 k- secondaryButton.isSupported(); // boolean
复制代码Functions : - import { isSecondaryButtonSupported } from '@telegram-apps/sdk';
4 y; W- D: L/ I/ ? I8 x1 ^ - - _- v# P+ f1 G' | X' v" X
- isSecondaryButtonSupported(); // boolean
复制代码 安装在使用该组件之前,有必要将其安装到配置正确的 属性中。 为此,请使用 mount 方法。 它将更新 isMounted 信号属性。 Variable : - import { secondaryButton } from '@telegram-apps/sdk';
9 K! }* r' e P; X: `6 V
1 o$ l: U" g+ M* O" m% f7 S7 q- secondaryButton.mount();
* Y* b; W3 Z; l# i6 M' e N4 l4 M - secondaryButton.isMounted(); // true
复制代码Functions : - import {
' G+ F4 @2 F& E3 t$ F - mountSecondaryButton,
1 a& x2 I! q; ? i$ B+ H# Z) Z - isSecondaryButtonMounted,
$ R' `7 k% d7 W - } from '@telegram-apps/sdk';
. O& n+ h! V. o9 j$ {; a
u. z0 m' m6 [ h9 `* d2 W- mountSecondaryButton(); }* T1 x6 h1 |; c: f3 T
- isSecondaryButtonMounted(); // true
复制代码 * q1 ]- S4 a, A/ k& c9 ]$ X9 E
要卸载,请使用 unmount 方法: Variable : - secondaryButton.unmount();; X* e0 b! ]1 \3 j/ a3 y
- secondaryButton.isMounted(); // false
复制代码Functions : - import {$ Q2 X# Y) G) A9 t5 A" J( T
- unmountSecondaryButton,& L [/ h3 ]7 R) y V0 p p6 T
- isSecondaryButtonMounted,
. Y* |, C8 ~3 F1 {4 O - } from '@telegram-apps/sdk';$ n# Z+ w' `1 c+ W
1 f: `6 p% C" b7 q1 v! a- unmountSecondaryButton();
; b1 @4 r/ M2 M; n# W$ J9 G7 `) {3 n) B - isSecondaryButtonMounted(); // false
复制代码WARNING 该组件的属性取决于 Mini App 和 Theme Params 组件的值。 具体来说,二级按钮使用 Mini App 的 bottomBarBgColor 和一些主题参数颜色。 在使用辅助按钮之前,请确保将这些组件安装到 。 设置属性要更新按钮属性,请使用 setParams 方法。 它接受一个带有可选 属性的对象,每个属性负责各自的按钮特性。 反过来,调用该方法会更新 ,如 backgroundColor, hasShineEffect, isVisible, isEnabled, isLoaderVisible, position, state, textColor 和 text。 Variable : - secondaryButton.setParams({
* N$ _5 D* k# k& i; o - backgroundColor: '#000000',
6 L. B+ c$ j, t! q - hasShineEffect: true,* H) P! R, v3 @
- isEnabled: true,; A# B* N" y) r& Q3 M+ f
- isLoaderVisible: true,
$ \% k# x7 r+ F% g4 z( W: E! m* } - isVisible: true,
9 g2 A& w- P% h* ^+ r - position: 'top',
, G+ s/ j; N# I5 y- Y - text: 'My text',
( R z7 P7 a% c, c4 ~ - textColor: '#ffffff'! J0 W- A" C! _# x7 @9 T
- });+ N2 o& o3 @0 z) K9 h- i2 R& V
- secondaryButton.backgroundColor(); // '#000000'
W4 W$ ~! `8 ?4 C8 J& M - secondaryButton.hasShineEffect(); // true
- ^& G: N3 _2 ] - secondaryButton.isEnabled(); // true c7 ]7 h- U; R/ S7 h2 h
- secondaryButton.isLoaderVisible(); // true9 ]0 d7 N+ q8 I. O B* k, h
- secondaryButton.isVisible(); // true
6 M2 O* H: J' V( G' B+ Z - secondaryButton.position(); // 'top'
6 Z# P5 @/ y' y; Y) J N, b2 X - secondaryButton.text(); // 'My text'
3 X+ p. j! d" N+ Y7 c, j7 t - secondaryButton.textColor(); // '#ffffff'
& o- Z- Q9 |" ? - ' `7 u6 s; i& n6 N2 ]1 v" \: ~
- secondaryButton.state();% Q, _7 t5 B! Y* k9 _
- // {5 D0 z7 M" p# `9 D
- // backgroundColor: '#000000',, `8 Q1 ~% R0 ]: D/ z4 A
- // hasShineEffect: true,
; x+ a# q E7 N- E - // isActive: true,; z& u1 }) C7 {; a7 L: X2 k9 R
- // isLoaderVisible: true,1 N$ {0 T. `4 ^5 L& K( I5 g# T
- // isVisible: true,
9 d7 j9 m$ ?+ v - // position: 'top',
, L) N' o7 e9 {1 _ - // text: 'My text',/ j$ r) I9 ~: x9 ]8 T
- // textColor: '#ffffff' I' C( ?- a) k0 q4 k4 L
- // }
复制代码Functions : - import {
( m2 i, l# J1 ^: Y4 J$ R - setSecondaryButtonParams,
! W v8 v$ E. P* {& @% F - secondaryButtonBackgroundColor,5 X. @7 z7 A5 D, t
- secondaryButtonHasShineEffect,+ d) W" P& H( p1 e. s
- isSecondaryButtonVisible,
0 i/ n8 p# h& Y/ n - isSecondaryButtonEnabled,1 C1 n- C8 ^& y" E) f$ t
- isSecondaryButtonLoaderVisible,
5 P. C t3 X! C4 J - secondaryButtonState,
; N7 h" _! ?/ U - secondaryButtonTextColor,: W5 f$ m1 K; V4 Y
- secondaryButtonText,/ ]" ^9 U K7 j. C9 J, H% ~
- secondaryButtonPosition,; J3 J& B. v, i3 h. b! v
- } from '@telegram-apps/sdk';
4 {9 T! B3 ^; ]4 \( g - 3 L5 K4 f9 l d- w: `
- setSecondaryButtonParams({
7 d6 O4 P% w4 i8 z0 g2 r4 g( ~- i - backgroundColor: '#000000',* b# l' `* A0 `, B3 d1 p
- hasShineEffect: true,
+ F- G {% E" _5 c- ` ]0 G - isEnabled: true,
5 c6 q7 h( j% X* W9 E8 R - isLoaderVisible: true,1 X) O* @4 V8 N4 _
- isVisible: true,5 p* [# |2 P, q9 b; z
- position: 'top',
" n6 y+ Y L+ S m5 s. a' Q, G - text: 'My text',$ ?1 c7 c6 O, k
- textColor: '#ffffff'+ C0 T6 }$ ^0 \8 @6 ~" Y7 d. e3 ]% T
- });& n; d; q( Y4 {% p; i. D) \' G6 j, X
- secondaryButtonBackgroundColor(); // '#000000'
: O( n5 u; W; J6 n - secondaryButtonHasShineEffect(); // true- ~. L- F: b" X( n" C! e8 g, X( l
- isSecondaryButtonEnabled(); // true& B% }- ?2 s% z- M8 G% k' i
- isSecondaryButtonLoaderVisible(); // true0 T" A/ X5 M3 m3 e9 Y
- isSecondaryButtonVisible(); // true7 @7 ~* z4 c/ E; l" v8 v
- secondaryButtonPosition(); // 'top'( }; }# C9 I8 S& R" ~' T1 j
- secondaryButtonText(); // 'My text'
$ H' ], t t* M' A - secondaryButtonTextColor(); // '#ffffff'2 y& \4 N7 F0 F2 L
/ f: N# O. a7 q0 s: A- X- secondaryButtonState();8 O4 v+ w1 I9 M; g% v9 }
- // {! k! |; w9 j' x- W; a. I
- // backgroundColor: '#000000',
5 N( M" S& g, q9 g1 e - // hasShineEffect: true,
! @" c2 E7 s# W6 F" S - // isActive: true,
3 S3 d9 M' a7 |- l5 G u! S U - // isLoaderVisible: true,1 U6 g7 H$ V6 A5 D/ _
- // isVisible: true,
8 m) @, w$ X6 R$ S) {0 v$ z - // position: 'top',
0 G2 Y8 ^0 C% D* P8 E4 v' { - // text: 'My text',
( u7 r% \4 a" k - // textColor: '#ffffff'
; U/ t# v- h. `+ _2 r; F( k - // }
复制代码 跟踪点击要添加按钮点击监听器,请使用 onClick 方法。 它返回一个函数,用于移除绑定的 监听器。 或者,您也可以使用 offClick 方法。 Variable : - function listener() {" [/ U5 e' M- N+ D) x' w* l
- console.log('Clicked!');3 m- s6 C# y& L
- }
, A e0 E* g5 t d0 K
+ D! N E9 c0 Z, H4 p- e/ C- const offClick = secondaryButton.onClick(listener);
$ u. Q/ Y& X1 i ~/ }- S8 G3 g" ?. n - offClick();. X& w8 R, ^0 r+ R! F
- // or/ r5 C9 I$ O' v9 _) C5 p& z
- secondaryButton.onClick(listener);
U( u8 ?+ F. ~" G- \% T' ] - secondaryButton.offClick(listener);
复制代码Functions : - import {
' c: r+ [& e" r" |- e - onSecondaryButtonClick,# R; ^( E2 ]5 y7 S5 y% W T! v
- offSecondaryButtonClick,
0 f0 I. _% ^( L3 B; p - } from '@telegram-apps/sdk';" Y2 j+ E/ A8 y2 G/ I& Q
- 4 j6 \5 ^0 ^% h3 k3 y, s$ q
- function listener() {
" ?" J; J {, V) [1 \ - console.log('Clicked!');
) O, L3 `( @; @, j0 Q - }
, X4 F& W( ?: ]3 Q
; K: l) ]& z0 A9 E- const offClick = onSecondaryButtonClick(listener);8 [3 x& Q* G0 ~% J! u
- offClick();. f4 v4 p; H! m. k* a( n# u& s
- // or. c9 F/ d! W% o& N9 e
- onSecondaryButtonClick(listener);
+ O2 F1 {* _( W - offSecondaryButtonClick(listener);
复制代码 + i3 w* {8 c: i" B4 x0 P
& v3 \5 E- `: H( P. [
|