@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: '你好!',
});
};
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 |