Alert
Examples
Statuses
Alert
has four statuses: success
, info
, warning
, and error
. You can specify different statuses using the status
prop.
Messages can either be specified in the default slot, or via the message
prop.
<template>
<article>
<veui-alert
class="alert"
status="success"
>
Your profile has been updated.
</veui-alert>
<veui-alert
class="alert"
status="info"
>
Press any key to continue...
</veui-alert>
<veui-alert
class="alert"
status="warning"
>
<code>slot-scope</code> is deprecated. Use <code>v-slot</code> instead.
</veui-alert>
<veui-alert
class="alert"
status="error"
message="Uncaught SyntaxError: Unexpected token +"
/>
</article>
</template>
<script>
import { Alert } from 'veui'
export default {
components: {
'veui-alert': Alert
}
}
</script>
<style lang="less" scoped>
.alert {
margin-bottom: 20px;
}
</style>
Multiple messages
You can specify the message
prop as an array to display multiple switchable messages.
Set the closable
prop to true
to allow the alert message to be closed by users. You can also use the close-label
prop to make the close button shown as specified text.
<template>
<article>
<veui-alert
type="info"
close-label="Got it"
closable
:open.sync="open"
:message="messages"
/>
<section v-if="!open">
<veui-button @click="open = true">
Open
</veui-button>
</section>
</article>
</template>
<script>
import { Alert, Button } from 'veui'
export default {
components: {
'veui-alert': Alert,
'veui-button': Button
},
data () {
return {
open: true,
messages: [
'Component data must be a function.',
'Prop definitions should be as detailed as possible.',
'Always use key with v-for.',
'Never use v-if on the same element as v-for.'
]
}
}
}
</script>
With title
Set the title
prop to specify the message title.
<template>
<article>
<veui-alert
class="alert"
status="success"
title="消息标题"
>
Your profile has been updated.
</veui-alert>
<veui-alert
class="alert"
status="success"
>
Your profile has been updated.
<template #title>
消息标题
</template>
</veui-alert>
</article>
</template>
<script>
import { Alert } from 'veui'
export default {
components: {
'veui-alert': Alert
}
}
</script>
<style lang="less" scoped>
.alert {
margin-bottom: 20px;
}
</style>
Extra content
Use the extra
slot to specify additional content after the message.
<template>
<article>
<veui-alert
class="alert"
status="success"
ui="strong"
message="恭喜你,你的请求已成功处理"
closable
>
<template #title>
恭喜你
</template>
<template #extra>
<veui-button ui="text">
查看详情
</veui-button>
</template>
恭喜你,你的请求已成功处理
</veui-alert>
</article>
</template>
<script>
import { Alert, Button } from 'veui'
export default {
components: {
'veui-alert': Alert,
'veui-button': Button
}
}
</script>
<style lang="less" scoped>
.alert {
margin-bottom: 20px;
}
</style>
API
Props
Name | Type | Default | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
status | string | 'success' | The contextual status of the alert message.
| ||||||||||
type | string | 'success' | Deprecated. Use status instead. | ||||||||||
title | string | - | Message title. | ||||||||||
message | string | Array<string> | - | Message content. When an array is passed, multiple messages will be displayed and switchable. | ||||||||||
closable | boolean | false | Whether to allow closing. | ||||||||||
open | boolean | true |
Whether the message is displayed. | ||||||||||
index | number | 0 |
The index of the currently displayed message when there are multiple messages. |
Slots
Name | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
default | Message content area. Default content: message text.
| ||||||||||||
title | The content area of the message title. | ||||||||||||
extra | The additional content area after the message. | ||||||||||||
content | The entire message area, including status icons, switch buttons, close buttons, etc. |
Icons
Name | Description |
---|---|
success | Success message. |
warning | Warning message. |
info | Informational message. |
error | Error message. |
prev | Previous message. |
next | Next message. |
close | Close the alert. |