Skip to content

toast

用于在插件窗口内显示非阻塞的瞬时提示信息。

导入

typescript
import { toast } from 'onin-sdk';

所需权限:此 API 目前无需特殊权限即可使用。

API

toast.show(message, options?)

显示一条基础提示。

typescript
await toast.show('操作完成');

参数:

字段类型必填说明
messagestring提示正文
optionsobject配置项
options.kindstring提示类型:'default' | 'success' | 'error' | 'warning' | 'info'
options.durationnumber持续时间(毫秒),默认 4000ms

toast.success(message, options?)

显示成功提示。

typescript
await toast.success('保存成功!');

toast.error(message, options?)

显示错误提示。

typescript
await toast.error('网络连接失败', { duration: 5000 });

toast.warning(message, options?)

显示警告提示。

typescript
await toast.warning('存储空间即将存满');

toast.info(message, options?)

显示通知提示。

typescript
await toast.info('已进入开发者模式');

示例

typescript
import { toast, http } from 'onin-sdk';

async function uploadData() {
  try {
    await toast.info('正在同步...', { duration: 2000 });
    const response = await http.post('/sync', { data: '...' });
    
    if (response.status === 200) {
      await toast.success('同步成功!');
    } else {
      await toast.error(`同步失败: ${response.status}`);
    }
  } catch (e) {
    await toast.error('连接服务器异常');
  }
}

基于 MIT 协议发布