遮罩层
v-overlay
组件用于强调特定元素或其中的一部分。 它向用户发出应用程序内状态更改的信号,可用于创建加载程序,对话框等。
用例
以最简单的形式,v-overlay
组件将在您的应用程序上添加暗淡的图层。
template script
<template>
<div class="text-center">
<v-btn
color="error"
@click="overlay = !overlay"
>
Show Overlay
</v-btn>
<v-overlay :value="overlay">
<v-btn
icon
@click="overlay = false"
>
<v-icon>mdi-close</v-icon>
</v-btn>
</v-overlay>
</div>
</template>
<script>
export default {
data: () => ({
overlay: false,
}),
}
</script>
API
从下面选择您想要的组件,并查看可用的属性、插槽、事件和函数。
实战场
template script
<template>
<v-row justify="center">
<v-col cols="12">
<v-row align="center">
<v-btn
class="mt-12"
color="primary"
@click="overlay = !overlay"
>
Show Overlay
</v-btn>
<v-overlay
:absolute="absolute"
:opacity="opacity"
:value="overlay"
:z-index="zIndex"
>
<v-btn
color="primary"
@click="overlay = false"
>
Hide Overlay
</v-btn>
</v-overlay>
</v-row>
</v-col>
<v-row justify="center">
<v-radio-group row>
<v-checkbox
v-model="absolute"
label="Absolute"
></v-checkbox>
<v-checkbox
v-model="overlay"
class="mx-6"
label="value"
></v-checkbox>
<v-text-field
v-model="opacity"
label="Opacity"
max="1"
min="0"
step=".01"
style="width: 125px"
type="number"
@keydown="false"
></v-text-field>
<v-text-field
v-model="zIndex"
label="z-index"
max="9999"
min="-9999"
step="1"
style="width: 125px"
type="number"
@keydown="false"
></v-text-field>
</v-radio-group>
</v-row>
</v-row>
</template>
<script>
export default {
data: () => ({
absolute: false,
opacity: 0.46,
overlay: false,
zIndex: 5,
}),
}
</script>
示例
下面是一些简单到复杂的例子。
绝对定位
absolute
遮罩层被放置在绝对位置,并包含在父元素中。
template script
<template>
<v-row align="center" justify="center">
<v-card height="300" width="250">
<v-row justify="center">
<v-btn
color="success"
class="mt-12"
@click="overlay = !overlay"
>
Show Overlay
</v-btn>
<v-overlay
:absolute="absolute"
:value="overlay"
>
<v-btn
color="success"
@click="overlay = false"
>
Hide Overlay
</v-btn>
</v-overlay>
</v-row>
</v-card>
</v-row>
</template>
<script>
export default {
data: () => ({
absolute: true,
overlay: false,
}),
}
</script>
透明度
opacity
允许您自定义 v-overlay
组件的透明度。
template script
<template>
<v-row align="center" justify="center">
<v-card height="300" width="250">
<v-row justify="center">
<v-btn
color="orange lighten-2"
class="mt-12"
@click="overlay = !overlay"
>
Show Overlay
</v-btn>
<v-overlay
:absolute="absolute"
:opacity="opacity"
:value="overlay"
>
<v-btn
color="orange lighten-2"
@click="overlay = false"
>
Hide Overlay
</v-btn>
</v-overlay>
</v-row>
</v-card>
</v-row>
</template>
<script>
export default {
data: () => ({
absolute: true,
opacity: 1,
overlay: false,
}),
}
</script>
Z 索引
使用 z-index
可以轻松更改 v-overlay
组件的堆栈顺序。
template script
<template>
<v-row justify="center">
<v-btn
class="white--text"
color="teal"
@click="overlay = !overlay"
>
Show Overlay
</v-btn>
<v-overlay
:z-index="zIndex"
:value="overlay"
>
<v-btn
class="white--text"
color="teal"
@click="overlay = false"
>
Hide Overlay
</v-btn>
</v-overlay>
</v-row>
</template>
<script>
export default {
data: () => ({
overlay: false,
zIndex: 0,
}),
}
</script>
Charcoal Vuetify Beanie
Stay warm with the new Premium Knit Vuetify Beanie available in black, navy and charcoal.
ads by Vuetify
](https://store.vuetifyjs.com/product/premium-charcoal-vuetify-beanie?ref=vuetifyjs.com)
加载器
使用 v-overlay
作为背景,添加进度组件来轻松创建自定义加载器。
template script
<template>
<div class="text-center">
<v-btn
color="deep-purple accent-4"
class="white--text"
@click="overlay = !overlay"
>
Launch Application
<v-icon right>mdi-open-in-new</v-icon>
</v-btn>
<v-overlay :value="overlay">
<v-progress-circular indeterminate size="64"></v-progress-circular>
</v-overlay>
</div>
</template>
<script>
export default {
data: () => ({
overlay: false,
}),
watch: {
overlay (val) {
val && setTimeout(() => {
this.overlay = false
}, 3000)
},
},
}
</script>
高级版
使用 v-hover,我们可以在信息卡上添加漂亮的稀松布,以及用户可以执行的其他操作。
template script
<template>
<v-hover>
<template v-slot:default="{ hover }">
<v-card
class="mx-auto"
max-width="344"
>
<v-img src="https://cdn.vuetifyjs.com/images/cards/forest-art.jpg"></v-img>
<v-card-text>
<h2 class="title primary--text">Magento Forests</h2>
Travel to the best outdoor experience on planet Earth. A vacation you will never forget!
</v-card-text>
<v-card-title>
<v-rating
:value="4"
dense
color="orange"
background-color="orange"
hover
class="mr-2"
></v-rating>
<span class="primary--text subtitle-2">64 Reviews</span>
</v-card-title>
<v-fade-transition>
<v-overlay
v-if="hover"
absolute
color="#036358"
>
<v-btn>See more info</v-btn>
</v-overlay>
</v-fade-transition>
</v-card>
</template>
</v-hover>
</template>
<script>
export default {
data: () => ({
overlay: false,
}),
}
</script>