@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 |
|
自版本: 1.0.0
Interfaces
ShowOptions
属性 | 类型 | 说明 | 默认值 | 版本 |
---|---|---|---|---|
text | string | 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 |