用于頁面中展示重要的提示信息。
常見于消息提示或警告框。
1.如何使用?
頁面中的非浮層元素,不會(huì)自動(dòng)消失。
//Alert 組件提供四種主題,由type屬性指定,默認(rèn)值為info。
<template>
<el-alert
title="成功提示的文案"
type="success">
</el-alert>
<el-alert
title="消息提示的文案"
type="info">
</el-alert>
<el-alert
title="警告提示的文案"
type="warning">
</el-alert>
<el-alert
title="錯(cuò)誤提示的文案"
type="error">
</el-alert>
</template>
2.主題
Alert 組件提供了兩個(gè)不同的主題:light
和dark
。
//通過設(shè)置effect屬性來改變主題,默認(rèn)為light。
<template>
<el-alert
title="成功提示的文案"
type="success"
effect="dark">
</el-alert>
<el-alert
title="消息提示的文案"
type="info"
effect="dark">
</el-alert>
<el-alert
title="警告提示的文案"
type="warning"
effect="dark">
</el-alert>
<el-alert
title="錯(cuò)誤提示的文案"
type="error"
effect="dark">
</el-alert>
</template>
3.自定義關(guān)閉按鈕
自定義關(guān)閉按鈕為文字或其他符號。
/*在 Alert 組件中,你可以設(shè)置是否可關(guān)閉,關(guān)閉按鈕的文本以及關(guān)閉時(shí)的回調(diào)函數(shù)。closable屬性決定是否可關(guān)閉,接受boolean,默認(rèn)為true。你可以設(shè)置close-text屬性來代替右側(cè)的關(guān)閉圖標(biāo),注意:close-text必須為文本。設(shè)置close事件來設(shè)置關(guān)閉時(shí)的回調(diào)。*/
<template>
<el-alert
title="不可關(guān)閉的 alert"
type="success"
:closable="false">
</el-alert>
<el-alert
title="自定義 close-text"
type="info"
close-text="知道了">
</el-alert>
<el-alert
title="設(shè)置了回調(diào)的 alert"
type="warning"
@close="hello">
</el-alert>
</template>
<script>
export default {
methods: {
hello() {
alert('Hello World!');
}
}
}
</script>
4.帶有 icon
表示某種狀態(tài)時(shí)提升可讀性。
//通過設(shè)置show-icon屬性來顯示 Alert 的 icon,這能更有效地向用戶展示你的顯示意圖。
<template>
<el-alert
title="成功提示的文案"
type="success"
show-icon>
</el-alert>
<el-alert
title="消息提示的文案"
type="info"
show-icon>
</el-alert>
<el-alert
title="警告提示的文案"
type="warning"
show-icon>
</el-alert>
<el-alert
title="錯(cuò)誤提示的文案"
type="error"
show-icon>
</el-alert>
</template>
5.文字居中
使用?center
?屬性讓文字水平居中
<template>
<el-alert
title="成功提示的文案"
type="success"
center
show-icon>
</el-alert>
<el-alert
title="消息提示的文案"
type="info"
center
show-icon>
</el-alert>
<el-alert
title="警告提示的文案"
type="warning"
center
show-icon>
</el-alert>
<el-alert
title="錯(cuò)誤提示的文案"
type="error"
center
show-icon>
</el-alert>
</template>
?6.帶有輔助性文字介紹
包含標(biāo)題和內(nèi)容,解釋更詳細(xì)的警告。文章來源:http://www.zghlxwxcb.cn/news/detail-696952.html
//除了必填的title屬性外,你可以設(shè)置description屬性來幫助你更好地介紹,我們稱之為輔助性文字。輔助性文字只能存放單行文本,會(huì)自動(dòng)換行顯示。
<template>
<el-alert
title="帶輔助性文字介紹"
type="success"
description="這是一句繞口令:黑灰化肥會(huì)揮發(fā)發(fā)灰黑化肥揮發(fā);灰黑化肥會(huì)揮發(fā)發(fā)黑灰化肥發(fā)揮。 黑灰化肥會(huì)揮發(fā)發(fā)灰黑化肥黑灰揮發(fā)化為灰……">
</el-alert>
</template>
?7.帶有 icon 和輔助性文字介紹
//這是一個(gè)同時(shí)具有 icon 和輔助性文字的樣例。
<template>
<el-alert
title="成功提示的文案"
type="success"
description="文字說明文字說明文字說明文字說明文字說明文字說明"
show-icon>
</el-alert>
<el-alert
title="消息提示的文案"
type="info"
description="文字說明文字說明文字說明文字說明文字說明文字說明"
show-icon>
</el-alert>
<el-alert
title="警告提示的文案"
type="warning"
description="文字說明文字說明文字說明文字說明文字說明文字說明"
show-icon>
</el-alert>
<el-alert
title="錯(cuò)誤提示的文案"
type="error"
description="文字說明文字說明文字說明文字說明文字說明文字說明"
show-icon>
</el-alert>
</template>
?文章來源地址http://www.zghlxwxcb.cn/news/detail-696952.html
到了這里,關(guān)于ElementUI淺嘗輒止22:Alert 警告的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!