Vue Bootstrap Alerts
Vue Alerts - Bootstrap 4 & Material Design
Note: This documentation is for an older version of Bootstrap (v.4). A
newer version is available for Bootstrap 5. We recommend migrating to the latest version of our product - Material Design for
Bootstrap 5.
Go to docs v.5
Bootstrap alerts are feedback messages which are displayed after specific actions preceded by the user. Length of the text is not limited.
With the right use of colors, they add some emotional weight to our information, ranging from a simple warning to critical system failure or from an operation success to a neutral information.
Basic examples
Alerts are available for any length of text, as well as an optional dismiss button. For proper styling, use one of the eight contextual props (e.g., color="success"
). For inline dismissal, use the dismiss
prop.
<template>
<mdb-container>
<mdb-alert color="primary">
This is a primary alert—check it out!
</mdb-alert>
<mdb-alert color="secondary">
This is a secondary alert—check it out!
</mdb-alert>
<mdb-alert color="success">
This is a success alert—check it out!
</mdb-alert>
<mdb-alert color="danger">
This is a danger alert—check it out!
</mdb-alert>
<mdb-alert color="warning">
This is a warning alert—check it out!
</mdb-alert>
<mdb-alert color="info">
This is a info alert—check it out!
</mdb-alert>
<mdb-alert color="light">
This is a light alert—check it out!
</mdb-alert>
<mdb-alert color="dark">
This is a dark alert—check it out!
</mdb-alert>
</mdb-container>
</template>
<script>
import { mdbContainer, mdbAlert } from 'mdbvue';
export default {
name: 'AlertPage',
components: {
mdbContainer,
mdbAlert
},
}
</script>
Conveying meaning to assistive technologies
Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies – such as screen readers. Ensure that information denoted by the color is either obvious from the content itself (e.g. the visible text), or is included through alternative means, such as additional text hidden with the
.sr-only
class.
Link color
Use the .alert-link
utility class to quickly provide matching colored links within any alert.
<template>
<mdb-container>
<mdb-alert color="primary">
This is a primary alert with <a href="#!" class="alert-link">an example link</a>. Give it a click if you like.
</mdb-alert>
<mdb-alert color="secondary">
This is a primary alert with <a href="#!" class="alert-link">an example link</a>. Give it a click if you like.
</mdb-alert>
<mdb-alert color="success">
This is a primary alert with <a href="#!" class="alert-link">an example link</a>. Give it a click if you like.
</mdb-alert>
<mdb-alert color="danger">
This is a primary alert with <a href="#!" class="alert-link">an example link</a>. Give it a click if you like.
</mdb-alert>
<mdb-alert color="warning">
This is a primary alert with <a href="#!" class="alert-link">an example link</a>. Give it a click if you like.
</mdb-alert>
<mdb-alert color="info">
This is a primary alert with <a href="#!" class="alert-link">an example link</a>. Give it a click if you like.
</mdb-alert>
<mdb-alert color="light">
This is a primary alert with <a href="#!" class="alert-link">an example link</a>. Give it a click if you like.
</mdb-alert>
<mdb-alert color="dark">
This is a primary alert with <a href="#!" class="alert-link">an example link</a>. Give it a click if you like.
</mdb-alert>
</mdb-container>
</template>
<script>
import { mdbContainer, mdbAlert } from 'mdbvue';
export default {
name: 'AlertPage',
components: {
mdbContainer,
mdbAlert
},
}
</script>
Additional content
Alerts can also contain additional HTML elements like headings, paragraphs and dividers.
Well done!
Aww yeah, you successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.
Whenever you need to, be sure to use margin utilities to keep things nice and tidy.
<template>
<mdb-alert color="success">
<h4 class="alert-heading">Well done!</h4>
<p>Aww yeah, you successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.</p>
<hr>
<p class="mb-0">Whenever you need to, be sure to use margin utilities to keep things nice and tidy.</p>
</mdb-alert>
</template>
<script>
import { mdbAlert } from 'mdbvue';
export default {
name: 'AlertPage',
components: {
mdbAlert
}
}
</script>
Dismissing
Using the Vue Alert component, it’s possible to dismiss any alert inline. You can see this in action with a live demo:
<template>
<mdb-alert color="warning" v-if="p1" @closeAlert="p1=false" dismiss>
<strong>Holy guacamole!</strong> You should check in on some of those fields below.
</mdb-alert>
</template>
<script>
import { mdbAlert } from 'mdbvue';
export default {
name: 'AlertPage',
components: {
mdbAlert
},
data() {
return {
p1: true
};
}
}
</script>
Vue Alert - API
In this section you will find advanced information about the Vue Alert component. You will learn which modules are required in this component and what are the possibilities of configuring the component.
Import statement
<script>
import { mdbAlert } from 'mdbvue';
</script>
API Reference: Alert Properties
The table below shows the configuration options of the MDBAlert component.
Name | Type | Default | Description | Example |
---|---|---|---|---|
tag |
String | div |
Sets alert's tag name | <mdb-alert tag="span" ... > |
color |
String | -- |
Customises colors | <mdb-alert color="warning" ... > |
dissmiss |
Boolean | false |
Should the alert have a close button | <mdb-alert dismiss ... > |
closeClass |
String | primary |
Sets classes for close button | <mdb-alert dissmiss closeClass="red-text" ... > |
enterAnimation |
String | -- |
Use our Animations classes to customize alert with regard to the way it enters the scene | <mdb-alert enterAnimatrion="flipInX" ... > |
leaveAnimation |
String | -- |
Use our Animations classes to customize alert with regard to the way it goes away | <mdb-alert leaveAnimatrion="rotateOutUpLeft" ... > |
API Reference: Alert Events
Name | Description | Example |
---|---|---|
beforeEnter |
This event gets emitted when alert is about to appear. |
<mdb-alert @beforeEnter={()=> alert('beforeEnter event')}>
|
enter |
This event gets takes place when alert appears. |
<mdb-alert @enter={()=> alert('enter event')}>
|
afterEnter |
This event happens once the alert is in place. |
<mdb-alert @afterEnter={()=> alert('afterEnter event')}>
|
enterCancelled |
This event takes place in case the transition has been interupted. |
<mdb-alert @enterCancelled={()=> alert('enterCancelled event')}>
|
beforeLeave |
This event gets emitted when alert is about to disappear. |
<mdb-alert @beforeLeave={()=> alert('beforeLeave event')}>
|
leave |
This event gets takes place when alert starts to get away. |
<mdb-alert @leave={()=> alert('leave event')}>
|
afterLeave |
This event happens once the alert is gone. |
<mdb-alert @afterLeave={()=> alert('afterLeave event')}>
|
leaveCancelled |
This event takes place in case the leaving transition has been interupted. |
<mdb-alert @leaveCancelled={()=> alert('leaveCancelled event')}>
|