跳到主要内容
版本:v7

@capacitor/toast

Toast API 提供通知弹出功能,用于向用户显示重要信息。

安装

npm install @capacitor/toast
npx cap sync

PWA 注意事项

Toast 插件需要 PWA Elements 才能正常工作。

示例

import { Toast } from '@capacitor/toast';

const showHelloToast = async () => {
await Toast.show({
text: 'Hello!',
});
};

API

show(...)

show(options: ShowOptions) => Promise<void>

在屏幕上显示 Toast

参数类型
options
ShowOptions

自从: 1.0.0


Interfaces

ShowOptions

属性类型描述默认值自从
textstring要在 Toast 上显示的文本1.0.0
duration'short' | 'long'Toast 的持续时间,可选 'short' (2000毫秒) 或 'long' (3500毫秒)'short'1.0.0
position'top' | 'center' | 'bottom'Toast 的位置。在 Android 12 及更新版本中,所有 Toast 都显示在底部。'bottom'1.0.0