TuToast 轻提示
深色半透明胶囊,top / center / bottom 三位置,自动关闭由父级定时。
轻提示:深色半透明胶囊 + 白字,top / center / bottom 三位置。完全受控:visible 由父级维护;组件不做自动关闭,父级在打开后自行 setTimeout 关闭(Web 与小程序均支持)。
属性
| 名称 | 类型 | 说明 |
|---|---|---|
visible | boolean | 是否显示(受控),默认 false。 |
content | string | 提示文案。 |
position | top | center | bottom | 出现位置,默认 center。 |
duration | number | 显示时长(毫秒,默认 2000),仅供父级参考决定何时关闭。 |
closable | boolean | 点击 toast 是否触发 close(可手动关闭场景)。 |
事件:close(仅 closable 为 true 时点击触发)。
点击按钮触发对应位置的轻提示,父级定时 1.6s 后自动隐藏 —— visible 完全受控。
实例
ts
// 组件只负责展示,时长由父级控制
createComponent({
component: TuToast,
props: { visible: this.state.toastVisible, content: '保存成功', position: 'center' },
});
this.state.toastVisible = true;
setTimeout(() => (this.state.toastVisible = false), 2000);