Skip to content

消息通知 ​

Toast 通知。可在任意位置通过 toast manager 调用;只需渲染一个 Toaster(AppLayout 中已包含)。

类型与位置 ​

类型与位置
vue
<div>
  <div class="thl-demo-row"><ThlButton variant="success" @click="toast.success('Saved successfully')">success</ThlButton><ThlButton variant="info" @click="toast.info('FYI', { title: 'Info' })">info</ThlButton><ThlButton variant="warning" @click="toast.warning('Careful')">warning</ThlButton><ThlButton variant="danger" @click="toast.error('Failed', { duration: 0 })">error (sticky)</ThlButton></div>
  <div class="thl-demo-row"><ThlButton v-for="p in positions" :key="p" size="sm" outline variant="primary" @click="toast.show({ message: p, position: p })">{{ p }}</ThlButton></div>
</div>
tsx
import { useToast } from '@thl-ui/react';
const toast = useToast();
toast.success('Saved successfully');
toast.info('FYI', { title: 'Info' });
toast.error('Failed', { duration: 0 });           // sticky
toast.show({ message: 'Hi', position: 'bottom-left', icon: 'bell' });
html
import { ThlToastService } from '@thl-ui/angular';
readonly toast = inject(ThlToastService);
this.toast.success('Saved successfully');
this.toast.error('Failed', { duration: 0 });
this.toast.show({ message: 'Hi', position: 'bottom-left' });

选项 ​

选项类型默认值
messagestring—
titlestring—
type'success' | 'info' | 'warning' | 'error' | 'default''default'
durationnumber(毫秒,0 = 不自动关闭)components.Toast.duration(3500)
positiontop-right · top-left · bottom-right · bottom-left · top-center · bottom-centercomponents.Toast.position
icon图标名称随类型而定
closablebooleantrue

max(默认 5)限制每个位置可见的 toast 数量。不使用 AppLayout 时,请渲染一次 <Toaster/> / <ThlToaster/> / <thl-toaster/>。

API ​

Toaster

<ThlToaster> · import { ThlToaster } from '@thl-ui/vue'

Prop类型默认值