W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
用于頁面中展示重要的提示信息。
頁面中的非浮層元素,不會自動消失。
Alert 組件提供四種主題,由type
屬性指定,默認值為info
。
render() {
return (
<div>
<Alert title="成功提示的文案" type="success" />
<Alert title="消息提示的文案" type="info" />
<Alert title="警告提示的文案" type="warning" />
<Alert title="錯誤提示的文案" type="error" />
</div>
)
}
自定義關(guān)閉按鈕為文字或其他符號。
在 Alert 組件中,你可以設(shè)置是否可關(guān)閉,關(guān)閉按鈕的文本以及關(guān)閉時的回調(diào)函數(shù)。closable
屬性決定是否可關(guān)閉,接受boolean
,默認為true
。你可以設(shè)置closeText
屬性來代替右側(cè)的關(guān)閉圖標,注意:closeText
必須為文本。設(shè)置onClose
事件來設(shè)置關(guān)閉時的回調(diào)。
render() {
return (
<div>
<Alert title="不可關(guān)閉的 alert" type="success" closable={false} />
<Alert title="自定義 close-text" type="info" closeText="知道了" />
<Alert title="設(shè)置了回調(diào)的 alert" type="warning" onClose={() => alert('Hello World!')}/>
</div>
)
}
表示某種狀態(tài)時提升可讀性。
通過設(shè)置showIcon
屬性來顯示 Alert 的 icon,這能更有效地向用戶展示你的顯示意圖。
render() {
return (
<div>
<Alert title="成功提示的文案" type="success" showIcon={true} />
<Alert title="消息提示的文案" type="info" showIcon={true} />
<Alert title="警告提示的文案" type="warning" showIcon={true} />
<Alert title="錯誤提示的文案" type="error" showIcon={true} />
</div>
)
}
包含標題和內(nèi)容,解釋更詳細的警告。
除了必填的title
屬性外,你可以設(shè)置description
屬性來幫助你更好地介紹,我們稱之為輔助性文字。輔助性文字只能存放單行文本,會自動換行顯示。
render() {
return (
<Alert
type="success"
title="帶輔助性文字介紹"
description="這是一句繞口令:黑灰化肥會揮發(fā)發(fā)灰黑化肥揮發(fā);灰黑化肥會揮發(fā)發(fā)黑灰化肥發(fā)揮。 黑灰化肥會揮發(fā)發(fā)灰黑化肥黑灰揮發(fā)化為灰……" />
)
}
最后,這是一個同時具有 icon 和輔助性文字的樣例。
render() {
return (
<div>
<Alert title="成功提示的文案" type="success" description="文字說明文字說明文字說明文字說明文字說明文字說明" showIcon={true} />
<Alert title="消息提示的文案" type="info" description="文字說明文字說明文字說明文字說明文字說明文字說明" showIcon={true} />
<Alert title="警告提示的文案" type="warning" description="文字說明文字說明文字說明文字說明文字說明文字說明" showIcon={true} />
<Alert title="錯誤提示的文案" type="error" description="文字說明文字說明文字說明文字說明文字說明文字說明" showIcon={true} />
</div>
)
}
參數(shù) | 說明 | 類型 | 可選值 | 默認值 |
---|---|---|---|---|
title | 標題,必選參數(shù) | string | — | — |
type | 主題 | string | success/warning/info/error | info |
description | 輔助性文字 | string | — | — |
closable | 是否可關(guān)閉 | boolean | — | true |
closeText | 關(guān)閉按鈕自定義文本 | string | — | — |
showIcon | 是否顯示圖標 | boolean | — | false |
事件名稱 | 說明 | 回調(diào)參數(shù) |
---|---|---|
onClose | 關(guān)閉alert時觸發(fā)的事件 | — |
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: