Skip to content

Message 訊息 ​

訊息以命令式 API 顯示全域 toast 回饋。請以 <gk-message-provider> 包住應用(或各示範),再呼叫 gkMessage;可用 destroy() / destroyAll() 管理生命週期。與 Alert 不同,Message 會自行從佇列移除。

示範 ​

基礎

觸發 gkMessage.info、success、warning、error。需要已連線的 gk-message-provider。
資訊成功警告錯誤

類型

類型:default、info、success、warning、error、loading。Loading 預設不會自動關閉;此示範會在 2 秒後 destroy()。
預設資訊成功警告錯誤載入中(2 秒)

可關閉

單次呼叫傳入 { closable: true }(或在 provider 上設定 closable)。關閉會從佇列移除該訊息。
可關閉訊息

持續時間

可覆寫單次呼叫的持續時間。Provider 預設為 3000 ms;0 表示不自動關閉。
1 秒持續時間 0

位置

僅在此示範的 provider 上設定 placement。可選:top、top-left、top-right、bottom、bottom-left、bottom-right。
右下角

全部銷毀

gkMessage.destroyAll() 會關閉作用中 provider 上的所有訊息。
資訊成功警告全部銷毀

API ​

gk-message-provider Props ​

Prop型別預設值
placement'top' | 'top-left' | 'top-right' | 'bottom' | 'bottom-left' | 'bottom-right''top'
durationnumber3000
closablebooleanfalse
keep-alive-on-hoverbooleanfalse
maxnumber—

gk-message-provider Slots ​

名稱說明
default應用/頁面內容

gkMessage ​

從 @gk-ui/core 匯入。需要已連線的 <gk-message-provider>。

方法簽名說明
create(content: string, options?: GkMessageOptions) => GkMessageReactive通用建立
info(content: string, options?: GkMessageOptions) => GkMessageReactivetype: 'info'
success(content: string, options?: GkMessageOptions) => GkMessageReactivetype: 'success'
warning(content: string, options?: GkMessageOptions) => GkMessageReactivetype: 'warning'
error(content: string, options?: GkMessageOptions) => GkMessageReactivetype: 'error'
loading(content: string, options?: GkMessageOptions) => GkMessageReactivetype: 'loading';預設 duration: 0
destroyAll() => void關閉作用中 provider 的全部訊息

GkMessageOptions: type、duration、closable、keepAliveOnHover、showIcon(預設 true)。

GkMessageReactive: { destroy: () => void }。

gk-message Props ​

Prop型別預設值
type'default' | 'info' | 'success' | 'warning' | 'error' | 'loading''default'
contentstring''
closablebooleanfalse
show-iconbooleantrue

gk-message Events ​

名稱說明
gk-close點擊關閉時觸發;bubbles;composed: true

CSS Parts (gk-message) ​

Part說明
base外層表面
icon圖示/轉圈欄
content文字內容
close關閉按鈕