提示框
v-alert
组件用于通过使用上下文类型图标和颜色向用户传达重要信息。这些默认类型有 4 种变量:success,info,warning 和 error。 默认图标可代表每种类型所传达的不同意思。 也可以自定义提示框的许多部分,例如 border
, icon
, 和 color
以适应几乎所有情况。
用例
最简单形式的提示框显示消息时是一个扁平的 sheets of paper。
API
从下面选择您想要的组件,并查看可用的属性、插槽、事件和函数。
示例
下面是一些简单到复杂的例子。
类型
type 属性提供 4 种默认的 v-alert
样式:success, info, warning, 和 error。每个样式都提供默认图标和颜色。默认颜色可通过 Vuetify’s theme 进行全局配置。
template
<template>
<div>
<v-alert type="success">
I'm a success alert.
</v-alert>
<v-alert type="info">
I'm an info alert.
</v-alert>
<v-alert type="warning">
I'm a warning alert.
</v-alert>
<v-alert type="error">
I'm an error alert.
</v-alert>
</div>
</template>
边框
border 属性支持将一个简单的边框添加到提示框的 4 个边。这可以和 color, dark, type 这些属性一起使用来为提示框提供强调作用。
template
<template>
<div>
<v-alert
border="top"
color="red lighten-2"
dark
>
I'm an alert with a top border and red color
</v-alert>
<v-alert
border="right"
color="blue-grey"
dark
>
I'm an alert with a right border and blue-grey color
</v-alert>
<v-alert
border="bottom"
color="pink darken-1"
dark
>
I'm an alert with a bottom border and pink color
</v-alert>
<v-alert
border="left"
color="indigo"
dark
>
I'm an alert with a border left type info
</v-alert>
</div>
</template>
彩色边框
colored-border prop 会移除警报背景,以突出 border prop 。如果设置了 type,它将使用类型的默认颜色。如果没有设置 color 或 type,颜色将默认为所应用的主题的反色(黑色代表浅色,白色/灰色代表深色)。
template
<template>
<div>
<v-alert
border="left"
colored-border
color="deep-purple accent-4"
elevation="2"
>
Aliquam eu nunc. Fusce commodo aliquam arcu. In consectetuer turpis ut velit. Nulla facilisi..
Morbi mollis tellus ac sapien. Fusce vel dui. Praesent ut ligula non mi varius sagittis. Vivamus consectetuer hendrerit lacus. Suspendisse enim turpis, dictum sed, iaculis a, condimentum nec, nisi.
</v-alert>
<v-alert
border="top"
colored-border
type="info"
elevation="2"
>
Vestibulum ullamcorper mauris at ligula. Nam pretium turpis et arcu. Ut varius tincidunt libero. Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo. Morbi nec metus.
</v-alert>
<v-alert
border="bottom"
colored-border
type="warning"
elevation="2"
>
Sed in libero ut nibh placerat accumsan. Phasellus leo dolor, tempus non, auctor et, hendrerit quis, nisi. Phasellus leo dolor, tempus non, auctor et, hendrerit quis, nisi. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero. Donec elit libero, sodales nec, volutpat a, suscipit non, turpis.
</v-alert>
<v-alert
border="right"
colored-border
type="error"
elevation="2"
>
Fusce commodo aliquam arcu. Pellentesque posuere. Phasellus tempus. Donec posuere vulputate arcu.
</v-alert>
</div>
</template>
密集
dense 属性会降低提示框的高度来制造出一个简单且紧凑的风格。如果和 border 属性一起使用,那么边界高度也会一起降低来保持风格统一。
template
<template>
<div>
<v-alert
dense
type="info"
>
I'm a dense alert with a <strong>type</strong> of info
</v-alert>
<v-alert
dense
text
type="success"
>
I'm a dense alert with the <strong>text</strong> prop and a <strong>type</strong> of success
</v-alert>
<v-alert
dense
border="left"
type="warning"
>
I'm a dense alert with the <strong>border</strong> prop and a <strong>type</strong> of warning
</v-alert>
<v-alert
dense
outlined
type="error"
>
I'm a dense alert with the <strong>outlined</strong> prop and a <strong>type</strong> of error
</v-alert>
</div>
</template>
可关闭
dismissible 属性将会在提示框的尾部添加一个关闭按钮。点击此按钮将会将它的值设置为 false 且隐藏提示框。你也能够通过绑定 v-model 的值为 true 来恢复提示框。关闭图标会自动应用 aria-label
,可以通过修改 close-label 属性或者改变本地设置 close 的值来进行更改它。浏览 Internationalization page 来了解如何全局修改你本地设置。
template script
<template>
<div>
<v-alert
v-model="alert"
border="left"
close-text="Close Alert"
color="deep-purple accent-4"
dark
dismissible
>
Aenean imperdiet. Quisque id odio. Cras dapibus. Pellentesque ut neque. Cras dapibus.
Vivamus consectetuer hendrerit lacus. Sed mollis, eros et ultrices tempus, mauris ipsum aliquam libero, non adipiscing dolor urna a orci. Sed mollis, eros et ultrices tempus, mauris ipsum aliquam libero, non adipiscing dolor urna a orci. Curabitur blandit mollis lacus. Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo.
</v-alert>
<div class="text-center">
<v-btn
v-if="!alert"
color="deep-purple accent-4"
dark
@click="alert = true"
>
Reset
</v-btn>
</div>
</div>
</template>
<script>
export default {
data () {
return {
alert: true,
}
},
}
</script>
图标
icon 属性允许你在提示框的开头添加图标。如果提供了 type,那么将会覆盖默认类型的图标。 此外设置 icon 属性为 false 将会完全移除图标。
template
<template>
<div>
<v-alert
color="#2A3B4D"
dark
icon="mdi-firework"
dense
>
Suspendisse enim turpis, dictum sed, iaculis a, condimentum nec, nisi. Vivamus quis mi. Quisque ut nisi. Maecenas malesuada.
</v-alert>
<v-alert
color="#C51162"
dark
icon="mdi-material-design"
border="right"
>
Phasellus blandit leo ut odio. Morbi mattis ullamcorper velit. Donec orci lectus, aliquam ut, faucibus non, euismod id, nulla. In ut quam vitae odio lacinia tincidunt.
</v-alert>
<v-alert
color="primary"
dark
icon="mdi-vuetify"
border="left"
prominent
>
Praesent congue erat at massa. Nullam vel sem. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Proin viverra, ligula sit amet ultrices semper, ligula arcu tristique sapien, a accumsan nisi mauris ac eros. Curabitur at lacus ac velit ornare lobortis.
</v-alert>
</div>
</template>
Blog Free
A simple template that features a clean interface for creating a blog or blog-like application.
ads by Vuetify
](https://blog-free.johnleider.com?ref=vuetifyjs.com)
轮廓
outlined 属性将会反转提示框的风格,它会继承当前应用的 color 并应用与文本和边框且将其背景透明化。
template
<template>
<div>
<v-alert
outlined
color="purple"
>
<div class="title">Lorem Ipsum</div>
<div>Maecenas ullamcorper, dui et placerat feugiat, eros pede varius nisi, condimentum viverra felis nunc et lorem. Duis vel nibh at velit scelerisque suscipit. Praesent blandit laoreet nibh. Aenean posuere, tortor sed cursus feugiat, nunc augue blandit nunc, eu sollicitudin urna dolor sagittis lacus. Etiam sollicitudin, ipsum eu pulvinar rutrum, tellus ipsum laoreet sapien, quis venenatis ante odio sit amet eros.</div>
</v-alert>
<v-alert
outlined
type="success"
text
>
Praesent venenatis metus at tortor pulvinar varius. Aenean commodo ligula eget dolor. Praesent ac massa at ligula laoreet iaculis. Vestibulum ullamcorper mauris at ligula.
</v-alert>
<v-alert
outlined
type="warning"
prominent
border="left"
>
Duis arcu tortor, suscipit eget, imperdiet nec, imperdiet iaculis, ipsum. Suspendisse non nisl sit amet velit hendrerit rutrum. Nullam vel sem. Pellentesque dapibus hendrerit tortor.
</v-alert>
</div>
</template>
突出
prominent 属性通过增加高度并向图标施加光晕来提供更明显的提示。当同时应用 prominent 和 dense 时,提示框将会呈现出普通的风格但是会 prominent 图标特效。
template
<template>
<div>
<v-alert
prominent
type="error"
>
<v-row align="center">
<v-col class="grow">Nunc nonummy metus. Nunc interdum lacus sit amet orci. Nullam dictum felis eu pede mollis pretium. Cras id dui.</v-col>
<v-col class="shrink">
<v-btn>Take action</v-btn>
</v-col>
</v-row>
</v-alert>
<v-alert
color="blue-grey"
dark
dense
icon="mdi-school"
prominent
>
Sed augue ipsum, egestas nec, vestibulum et, malesuada adipiscing, dui. Aenean ut eros et nisl sagittis vestibulum. Sed aliquam ultrices mauris. Donec vitae orci sed dolor rutrum auctor.
</v-alert>
<v-alert
icon="mdi-shield-lock-outline"
prominent
text
type="info"
>
Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Sed in libero ut nibh placerat accumsan.. Curabitur blandit mollis lacus. Curabitur blandit mollis lacus.
</v-alert>
</div>
</template>
文本
text 属性是一个简单的提示框变量,它对所提供的颜色使用不透明的背景。 类似于其他样式的属性,text 可与 dense, prominent 和 outlined 等其他属性结合使用,以创建独特的定制组件。
template
<template>
<div>
<v-alert
text
color="info"
>
<h3 class="headline">Lorem Ipsum</h3>
<div>Maecenas nec odio et ante tincidunt tempus. Sed mollis, eros et ultrices tempus, mauris ipsum aliquam libero, non adipiscing dolor urna a orci. Proin viverra, ligula sit amet ultrices semper, ligula arcu tristique sapien, a accumsan nisi mauris ac eros. Curabitur turpis.</div>
<v-divider
class="my-4 info"
style="opacity: 0.22"
></v-divider>
<v-row
align="center"
no-gutters
>
<v-col class="grow">Proin magna. Vivamus in erat ut urna cursus vestibulum. Etiam imperdiet imperdiet orci.</v-col>
<v-spacer></v-spacer>
<v-col class="shrink">
<v-btn
color="info"
outlined
>
Okay
</v-btn>
</v-col>
</v-row>
</v-alert>
<v-alert
text
outlined
color="deep-orange"
icon="mdi-fire"
>
Nullam tincidunt adipiscing enim. In consectetuer turpis ut velit. Maecenas egestas arcu quis ligula mattis placerat. Praesent metus tellus, elementum eu, semper a, adipiscing nec, purus.
</v-alert>
<v-alert
text
dense
color="teal"
icon="mdi-clock-fast"
border="left"
>
Vestibulum ullamcorper mauris at ligula. Nulla porta dolor. Vestibulum facilisis, purus nec pulvinar iaculis, ligula mi congue nunc, vitae euismod ligula urna in dolor. Curabitur at lacus ac velit ornare lobortis.
</v-alert>
<v-alert
text
prominent
type="error"
icon="mdi-cloud-alert"
>
Praesent blandit laoreet nibh. Praesent nonummy mi in odio. Phasellus tempus. Mauris turpis nunc, blandit et, volutpat molestie, porta ut, ligula. Duis leo.
</v-alert>
</div>
</template>
过渡
transition 属性可让你向提示框应用一个过渡,该动画在隐藏和显示组件时可见。你可以在 Vuetify’s prebuilt transitions 浏览更多信息或者查看如何 create your own。
template script
<template>
<div>
<div class="text-center mb-4">
<v-btn
color="primary"
@click="alert = !alert"
>
Toggle
</v-btn>
</div>
<v-alert
:value="alert"
color="pink"
dark
border="top"
icon="mdi-home"
transition="scale-transition"
>
Phasellus tempus. Fusce ac felis sit amet ligula pharetra condimentum. In dui magna, posuere eget, vestibulum et, tempor auctor, justo. Pellentesque posuere. Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo.
Phasellus nec sem in justo pellentesque facilisis. Phasellus magna. Cras risus ipsum, faucibus ut, ullamcorper id, varius ac, leo. In hac habitasse platea dictumst. Praesent turpis.
</v-alert>
</div>
</template>
<script>
export default {
data () {
return {
alert: true,
}
},
}
</script>
Twitter 提醒
通过将 color、dismissible、border、elevation、icon 和 colored-border props 组合在一起,你可以创建时尚的自定义提醒,比如这个 twitter 通知。
template script
<template>
<div>
<v-alert
v-model="alert"
dismissible
color="cyan"
border="left"
elevation="2"
colored-border
icon="mdi-twitter"
>
You've got <strong>5</strong> new updates on your timeline!.
</v-alert>
<div class="text-center">
<v-btn
v-if="!alert"
dark
@click="alert = true"
>
Reset Alert
</v-btn>
</div>
</div>
</template>
<script>
export default {
data () {
return {
alert: true,
}
},
}
</script>
无障碍
默认情况下,v-alert
被分配到 alert 的 WAI-ARIA 作用,这表示提示框是一个活动区域,包含重要且通常对时间敏感的信息。当使用 dismissible 属性时,关闭图标将会接受相应的 aria-label
。可以通过修改 close-label 属性来修改它或者全局自定义 Internationalization 默认值来修改 close 属性。