辅助按钮 负责 Telegram 迷你应用程序二级按钮的💠组件。 检查支持要检查当前 Telegram 迷你应用程序版本是否支持辅助按钮,请使用 isSupported 方法: Variable : - import { secondaryButton } from '@telegram-apps/sdk';
/ A% `5 y7 @4 O6 _- T: d - ! k* h7 k7 x0 V* ~0 l8 D" `
- secondaryButton.isSupported(); // boolean
复制代码Functions : - import { isSecondaryButtonSupported } from '@telegram-apps/sdk';: t' P! Y2 h- B2 I! ]: G. o {8 {
/ P' u8 C( a) W- isSecondaryButtonSupported(); // boolean
复制代码 安装在使用该组件之前,有必要将其安装到配置正确的 属性中。 为此,请使用 mount 方法。 它将更新 isMounted 信号属性。 Variable : - import { secondaryButton } from '@telegram-apps/sdk';" J S6 Y1 p0 {
- . f% m6 n& h2 |
- secondaryButton.mount();
+ [9 x9 \0 i4 ]5 J - secondaryButton.isMounted(); // true
复制代码Functions : - import {
' {( ^+ q! _$ {2 C1 J0 v - mountSecondaryButton,) q7 v4 O0 U$ Z% u4 V
- isSecondaryButtonMounted,. y4 ~4 |: h1 s, z
- } from '@telegram-apps/sdk';4 i& l' e! T' b, q* ]
- 2 j( E! S4 }" J0 O) H
- mountSecondaryButton();
7 r! Y6 X8 Y# ]& a: f6 O - isSecondaryButtonMounted(); // true
复制代码
1 }- J# f7 [5 n/ K- }" s要卸载,请使用 unmount 方法: Variable : - secondaryButton.unmount();
- f+ s2 o$ W$ e# j5 z - secondaryButton.isMounted(); // false
复制代码Functions : - import {
+ |+ a& a) I! a1 a8 v7 S - unmountSecondaryButton,
0 S5 O# w' i5 n - isSecondaryButtonMounted, ?3 f6 X% Z- S
- } from '@telegram-apps/sdk';
+ T; `# w7 ^. h9 K
& n! d+ J" P$ @' j- unmountSecondaryButton();0 k9 _! U/ w1 w5 O9 S
- isSecondaryButtonMounted(); // false
复制代码WARNING 该组件的属性取决于 Mini App 和 Theme Params 组件的值。 具体来说,二级按钮使用 Mini App 的 bottomBarBgColor 和一些主题参数颜色。 在使用辅助按钮之前,请确保将这些组件安装到 。 设置属性要更新按钮属性,请使用 setParams 方法。 它接受一个带有可选 属性的对象,每个属性负责各自的按钮特性。 反过来,调用该方法会更新 ,如 backgroundColor, hasShineEffect, isVisible, isEnabled, isLoaderVisible, position, state, textColor 和 text。 Variable : - secondaryButton.setParams({/ P) o7 B1 e$ C3 w. ~( z
- backgroundColor: '#000000',
c* p" n! A/ j8 x( F! ~ - hasShineEffect: true,7 b, P- |# i" I; [# E! ?7 w
- isEnabled: true,
f- } m3 L+ b8 T. f- w - isLoaderVisible: true,
7 V' i/ S9 L4 H6 w z* c - isVisible: true,
& Z/ ^* d: ?6 P0 T" C - position: 'top',
' n z4 I4 z- w5 p8 @3 h; ~+ | - text: 'My text',; H# |. A( W6 ^
- textColor: '#ffffff'
4 X' A% R* T# G) d& J( r9 M - });/ R; \ q$ n3 K# O0 o1 _
- secondaryButton.backgroundColor(); // '#000000') t9 D1 j+ Q" U2 r) V! X
- secondaryButton.hasShineEffect(); // true! o( S1 ]; v( s+ {0 [' j
- secondaryButton.isEnabled(); // true2 m3 ]6 e, v$ N# m6 n j3 [
- secondaryButton.isLoaderVisible(); // true6 G! A6 f- Y% k, D
- secondaryButton.isVisible(); // true
0 u/ m0 T$ ^8 b - secondaryButton.position(); // 'top'
G4 e& V, f5 L8 Q# B" p - secondaryButton.text(); // 'My text'
: A0 ?. p: m7 R - secondaryButton.textColor(); // '#ffffff'
1 v; |& E! {1 g" a - 5 |# v& W( \/ m3 |2 Z A8 ~! N
- secondaryButton.state();
9 p6 c3 \2 u" ] - // {
, p/ X4 o0 I5 ^* u: Q [ - // backgroundColor: '#000000',3 t9 e9 p3 \( E& z) ]
- // hasShineEffect: true,
, H; F. }. l. k7 n/ @0 g! G - // isActive: true,) f; o7 N7 I2 S) W( `4 ~
- // isLoaderVisible: true,
0 _6 I8 O8 Z7 Q: B& J: P U - // isVisible: true,4 l7 m$ {: {3 q4 }7 \/ f
- // position: 'top',
) M/ b" x% I" C* E - // text: 'My text',! v0 D( k% |4 f. t* v6 N# W
- // textColor: '#ffffff'* J* X! f' m/ P& P
- // }
复制代码Functions : - import {
r0 ~# U: [% z5 s - setSecondaryButtonParams,
) Z- l Z. Y# U: w6 g% t! W/ i - secondaryButtonBackgroundColor,
+ p" b1 H. N$ s' z! b7 O - secondaryButtonHasShineEffect,' A: r7 X1 P/ j9 [9 d
- isSecondaryButtonVisible,
, T3 ~) X. X) U# A1 h4 Y - isSecondaryButtonEnabled,
, k- m) J! i+ D1 {' ~ - isSecondaryButtonLoaderVisible,9 E8 @( T5 ^: H$ w
- secondaryButtonState,
1 o5 ~5 e$ @' o6 F/ E) O - secondaryButtonTextColor,
7 ]' P8 C6 U1 G0 u$ L - secondaryButtonText,5 N, k/ H. E) R7 X0 S
- secondaryButtonPosition,6 S6 V9 ?/ w" @3 A
- } from '@telegram-apps/sdk';
/ E2 G) d/ q, e" H, k* s
9 C9 m* V! n2 |$ U. @- setSecondaryButtonParams({
. t$ R- r9 X, f! B7 }' d - backgroundColor: '#000000',
( e# n# ^+ A9 h6 r+ M: F1 ] - hasShineEffect: true,
3 z# S4 Z7 B* b; t F' x: P$ ?/ R - isEnabled: true,/ ^8 M9 K' Y3 r6 }
- isLoaderVisible: true,
, W& g8 ~2 n3 ^) ~% h1 K - isVisible: true,
+ f$ l! u( y" l6 D* |/ p, L - position: 'top',( u5 p+ k5 ?0 [7 w/ F6 k
- text: 'My text',
6 ^0 q7 N: [- O3 t* {3 | - textColor: '#ffffff'
. I- }+ u0 Y) z' O* b; B - });
7 u k! ?# W' X8 |; L - secondaryButtonBackgroundColor(); // '#000000'
8 w5 K# |9 i! E5 u: ^ - secondaryButtonHasShineEffect(); // true
( M1 F* H! z! T% }/ {6 Z - isSecondaryButtonEnabled(); // true
* L: x5 G+ e* J" I& |) a - isSecondaryButtonLoaderVisible(); // true
& F+ S; I, A0 |" o0 n0 L; Y( ^ - isSecondaryButtonVisible(); // true0 W. O- o$ R% [
- secondaryButtonPosition(); // 'top'5 X- k1 }5 F* g, x$ m
- secondaryButtonText(); // 'My text'* y; o b2 |( _: w6 b
- secondaryButtonTextColor(); // '#ffffff'
Q, f% b) X9 e; P - 0 W: M$ z7 j4 o
- secondaryButtonState();6 K. Z( W6 S$ m) i* a* q
- // {
: Z' t1 D. @$ o6 a9 _, b; e6 x - // backgroundColor: '#000000',
. a X0 q' {3 O5 I0 {( Z6 _) f - // hasShineEffect: true,
5 w. P/ t u* h( ?2 r3 O - // isActive: true,& J. `: q+ n9 M- l( V
- // isLoaderVisible: true,
8 }2 e, [' l! p6 r - // isVisible: true,( {' C) O$ {! b, {6 C
- // position: 'top',5 U$ K' Q0 D# V% X2 M# V( G& Q
- // text: 'My text',7 a, _( E4 O" e& s
- // textColor: '#ffffff'- ~3 g5 _, _' ^# b+ }4 J
- // }
复制代码 跟踪点击要添加按钮点击监听器,请使用 onClick 方法。 它返回一个函数,用于移除绑定的 监听器。 或者,您也可以使用 offClick 方法。 Variable : - function listener() {$ a6 w. u% g4 |+ H# `, O
- console.log('Clicked!');
& `5 j, v$ O( i! X0 H+ Z - }; L" N# b2 l/ j: X# W2 t9 G/ b
- ) \ h: @7 q$ |5 _2 X! {5 ]: ^
- const offClick = secondaryButton.onClick(listener);# a2 A/ _" W. J9 w A% V
- offClick();/ v6 [* k0 ^( ~) L, k8 X
- // or1 a5 X! e, W6 w6 P4 j. l
- secondaryButton.onClick(listener);5 V3 o$ f- \ E" O6 ]/ D" w
- secondaryButton.offClick(listener);
复制代码Functions : - import {7 Z1 G8 y; [4 R9 K/ ^1 [& M
- onSecondaryButtonClick,7 {; g) n* r( U- H' V- V
- offSecondaryButtonClick,- R# c$ M% e, y4 Y
- } from '@telegram-apps/sdk';
5 ^& k! m3 {3 u
6 x- s9 i0 {7 r" H" W, S- function listener() {
7 H9 o5 o- d' p( v' u, }, ] - console.log('Clicked!');2 [& j1 ?7 D0 ^
- }
3 u' E s1 U1 v1 l5 ]3 g - ( m8 j8 i# |1 T9 U5 C
- const offClick = onSecondaryButtonClick(listener);9 x+ E, B: v5 ]
- offClick();
t, g5 u Q; y; \# `1 y - // or$ h$ v9 Y- T3 |* s
- onSecondaryButtonClick(listener);: |* ?, ^+ g2 H7 z# w$ I7 S: d$ E
- offSecondaryButtonClick(listener);
复制代码
# v8 d2 q+ H. O; d7 g
a0 p5 H- l6 k& Q' y |