Provide contextual feedback messages for typical user actions with the handful of available and flexible alert messages.
Alerts are available for any length of text, as well as an optional close button. For proper styling, use one of the eight required contextual classes (e.g., theme="success"
).
<template>
<Alert theme="primary">
A simple primary alert—check it out!
</Alert>
<Alert theme="secondary">
A simple secondary alert—check it out!
</Alert>
<Alert theme="success">
A simple success alert—check it out!
</Alert>
<Alert theme="danger">
A simple danger alert—check it out!
</Alert>
<Alert theme="warning">
A simple warning alert—check it out!
</Alert>
<Alert theme="info">
A simple info alert—check it out!
</Alert>
<Alert theme="light">
A simple light alert—check it out!
</Alert>
<Alert theme="dark">
A simple dark alert—check it out!
</Alert>
</template>
Use the AlertLink
compoennt utility class to quickly provide matching colored links within any alert.
<template>
<Alert theme="primary">
A simple primary alert with
<AlertLink>an example link</AlertLink>
. Give it a click if you like.
</Alert>
<Alert theme="secondary">
A simple secondary alert with
<AlertLink>an example link</AlertLink>
. Give it a click if you like.
</Alert>
<Alert theme="success">
A simple success alert with
<AlertLink>an example link</AlertLink>
. Give it a click if you like.
</Alert>
<Alert theme="danger">
A simple danger alert with
<AlertLink>an example link</AlertLink>
. Give it a click if you like.
</Alert>
<Alert theme="warning">
A simple warning alert with
<AlertLink>an example link</AlertLink>
. Give it a click if you like.
</Alert>
<Alert theme="info">
A simple info alert with
<AlertLink>an example link</AlertLink>
. Give it a click if you like.
</Alert>
<Alert theme="light">
A simple light alert with
<AlertLink>an example link</AlertLink>
. Give it a click if you like.
</Alert>
<Alert theme="dark">
A simple dark alert with
<AlertLink>an example link</AlertLink>
. Give it a click if you like.
</Alert>
</template>
Alerts can also contain additional HTML elements like headings, paragraphs and dividers.
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>
<Alert theme="success">
<AlertHeading>Well done!</AlertHeading>
<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>
<b-p margin="b-0">
Whenever you need to, be sure to use margin utilities to keep things nice
and tidy.
</b-p>
</Alert>
</template>
<template>
<Alert
theme="primary"
flex
align-items="center"
>
<Icon
v-bootstrap
name="bi:exclamation-triangle-fill"
flex="shrink-0"
margin="e-2"
aria-label="Warning:"
/>
<div>An example alert with an icon</div>
</Alert>
</template>
Need more than one icon for your alerts? Consider using more NuxtIcon and making a SVG sprite like so to easily reference the same icons repeatedly.
<template>
<Alert
theme="primary"
flex
align-items="center"
>
<Icon
v-bootstrap
name="bi:info-circle-fill"
color="currentColor"
flex="shrink-0"
margin="e-2"
aria-label="Info:"
/>
<div>An example alert with an icon</div>
</Alert>
<Alert
theme="success"
flex
align-items="center"
>
<Icon
v-bootstrap
name="bi:check-circle-fill"
color="currentColor"
flex="shrink-0"
margin="e-2"
aria-label="Success:"
/>
<div>An example success alert with an icon</div>
</Alert>
<Alert
theme="warning"
flex
align-items="center"
>
<Icon
v-bootstrap
name="bi:exclamation-triangle-fill"
color="currentColor"
flex="shrink-0"
margin="e-2"
aria-label="Warning:"
/>
<div>An example warning alert with an icon</div>
</Alert>
<Alert
theme="danger"
flex
align-items="center"
>
<Icon
v-bootstrap
name="bi:exclamation-triangle-fill"
color="currentColor"
flex="shrink-0"
margin="e-2"
aria-label="Danger:"
/>
<div>An example danger alert with an icon</div>
</Alert>
</template>
Using the CloseButton
components, it's possible to dismiss any alert inline. Here's how:
You can see this in action with a live demo:
<template>
<Alert
theme="warning"
dismissible
fade
>
<strong>Holy guacamole!</strong>
You should check in on some of those fields below.
<CloseButton dismiss="alert" />
</Alert>
</template>
Dismissal can be achieved with the data attribute on a button within the alert as demonstrated below:
<template>
<Alert
theme="warning"
dismissible
fade
>
<b-button
button="primary"
dismiss="alert"
>
Close
</b-button>
<strong>Holy guacamole!</strong>
You should check in on some of those fields below.
<CloseButton dismiss="alert" />
</Alert>
</template>
or on a button outside the alert using the data-bs-target as demonstrated below:
<template>
<Alert
id="my-alert"
theme="warning"
dismissible
fade
>
<strong>Holy guacamole!</strong>
You should check in on some of those fields below.
</Alert>
<b-button
button="primary"
dismiss="alert"
target="#my-alert"
>
Close
</b-button>
</template>
Method | Description |
---|---|
toggle | Manual switching |
show | Manually show |
hide | Manually hide |
dismiss | Manually hide |