窗口
v-window
组件提供将内容从一个窗口转换到另一个窗口的基础功能。其他组件,如 v-tabs
, v-carousel
和 v-stepper
在它们的核心中利用了这个组件。
用例
v-window
被设计成可以轻松地循环浏览内容,它提供了一个简单的接口来创建真正的自定义实现。
template script
<template>
<v-row align="center">
<v-item-group
v-model="window"
class="shrink mr-6"
mandatory
tag="v-flex"
>
<v-item
v-for="n in length"
:key="n"
v-slot:default="{ active, toggle }"
>
<div>
<v-btn
:input-value="active"
icon
@click="toggle"
>
<v-icon>mdi-record</v-icon>
</v-btn>
</div>
</v-item>
</v-item-group>
<v-col>
<v-window
v-model="window"
class="elevation-1"
vertical
>
<v-window-item
v-for="n in length"
:key="n"
>
<v-card flat>
<v-card-text>
<v-row class="mb-4" align="center">
<v-avatar color="grey" class="mr-4"></v-avatar>
<strong class="title">Title {{ n }}</strong>
<v-spacer></v-spacer>
<v-btn icon>
<v-icon>mdi-account</v-icon>
</v-btn>
</v-row>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</v-card-text>
</v-card>
</v-window-item>
</v-window>
</v-col>
</v-row>
</template>
<script>
export default {
data: () => ({
length: 3,
window: 0,
}),
}
</script>
API
从下面选择您想要的组件,并查看可用的属性、插槽、事件和函数。
实战场
template script
<template>
<v-row align="center">
<v-row justify="space-around">
<v-switch v-model="autorun" class="ma-2" label="Automatic switching"></v-switch>
<v-switch v-model="showArrows" class="ma-2" label="Show arrows"></v-switch>
<v-switch v-model="vertical" class="ma-2" label="Vertical"></v-switch>
<v-switch v-model="reverse" class="ma-2" label="Reverse"></v-switch>
</v-row>
<v-window
v-model="window"
class="elevation-1"
:vertical="vertical"
:show-arrows="showArrows"
:reverse="reverse"
>
<v-window-item
v-for="n in length"
:key="n"
>
<v-card flat>
<v-card-text>
<v-row class="mb-4" align="center">
<v-avatar color="grey" class="mr-4"></v-avatar>
<strong class="title">Title {{ n }}</strong>
<v-spacer></v-spacer>
<v-btn icon>
<v-icon>mdi-account</v-icon>
</v-btn>
</v-row>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</v-card-text>
</v-card>
</v-window-item>
</v-window>
</v-row>
</template>
<script>
export default {
data: () => ({
length: 3,
window: 0,
showArrows: false,
vertical: false,
reverse: false,
autorun: false,
}),
created () {
setInterval(() => {
if (!this.autorun) return
if (++this.window >= this.length) this.window = 0
}, 1000)
},
}
</script>
示例
下面是一些简单到复杂的例子。
垂直
v-window
可以是垂直的。 垂直窗口具有 Y 轴过渡而不是 X 轴过渡。
template script
<template>
<v-card flat tile>
<v-window v-model="onboarding" vertical>
<v-window-item
v-for="n in length"
:key="`card-${n}`"
>
<v-card
color="grey"
height="200"
>
<v-row
class="fill-height"
align="center"
justify="center"
tag="v-card-text"
>
<h1 style="font-size: 5rem;" class="white--text">Slide {{ n }}</h1>
</v-row>
</v-card>
</v-window-item>
</v-window>
<v-card-actions class="justify-space-between">
<v-btn
text
@click="prev"
>
<v-icon>mdi-chevron-left</v-icon>
</v-btn>
<v-item-group
v-model="onboarding"
class="text-center"
mandatory
>
<v-item
v-for="n in length"
:key="`btn-${n}`"
v-slot:default="{ active, toggle }"
>
<v-btn
:input-value="active"
icon
@click="toggle"
>
<v-icon>mdi-record</v-icon>
</v-btn>
</v-item>
</v-item-group>
<v-btn
text
@click="next"
>
<v-icon>mdi-chevron-right</v-icon>
</v-btn>
</v-card-actions>
</v-card>
</template>
<script>
export default {
data: () => ({
length: 3,
onboarding: 0,
}),
methods: {
next () {
this.onboarding = this.onboarding + 1 === this.length
? 0
: this.onboarding + 1
},
prev () {
this.onboarding = this.onboarding - 1 < 0
? this.length - 1
: this.onboarding - 1
},
},
}
</script>
反转
反转 v-window
总是显示反向转换。
template script
<template>
<v-card flat tile>
<v-window v-model="onboarding" reverse>
<v-window-item
v-for="n in length"
:key="`card-${n}`"
>
<v-card
color="grey"
height="200"
>
<v-row
class="fill-height"
align="center"
justify="center"
tag="v-card-text"
>
<h1 style="font-size: 5rem;" class="white--text">Slide {{ n }}</h1>
</v-row>
</v-card>
</v-window-item>
</v-window>
<v-card-actions class="justify-space-between">
<v-btn
text
@click="prev"
>
<v-icon>mdi-chevron-left</v-icon>
</v-btn>
<v-item-group
v-model="onboarding"
class="text-center"
mandatory
>
<v-item
v-for="n in length"
:key="`btn-${n}`"
v-slot:default="{ active, toggle }"
>
<v-btn
:input-value="active"
icon
@click="toggle"
>
<v-icon>mdi-record</v-icon>
</v-btn>
</v-item>
</v-item-group>
<v-btn
text
@click="next"
>
<v-icon>mdi-chevron-right</v-icon>
</v-btn>
</v-card-actions>
</v-card>
</template>
<script>
export default {
data: () => ({
length: 3,
onboarding: 0,
}),
methods: {
next () {
this.onboarding = this.onboarding + 1 === this.length
? 0
: this.onboarding + 1
},
prev () {
this.onboarding = this.onboarding - 1 < 0
? this.length - 1
: this.onboarding - 1
},
},
}
</script>
Material Kit
A complete set of Material Inspired themes built with Vuetify on top of Vue CLI.
ads by Vuetify
](https://store.vuetifyjs.com/product/material-kit-theme?ref=vuetifyjs.com)
入职
v-window
使它很容易创建自定义组件,如不同风格的幻灯片。
template script
<template>
<v-card
color="black"
dark
flat
tile
>
<v-window v-model="onboarding">
<v-window-item
v-for="n in length"
:key="`card-${n}`"
>
<v-card
color="transparent"
height="200"
>
<v-row
class="fill-height"
align="center"
justify="center"
tag="v-card-text"
>
Transparent themed, for background-imaged slides. Background color black added for demonstration purposes.
</v-row>
</v-card>
</v-window-item>
</v-window>
<v-card-actions class="justify-space-between">
<v-btn
text
@click="prev"
>
<v-icon>mdi-chevron-left</v-icon>
</v-btn>
<v-item-group
v-model="onboarding"
class="text-center"
mandatory
>
<v-item
v-for="n in length"
:key="`btn-${n}`"
v-slot:default="{ active, toggle }"
>
<v-btn
:input-value="active"
icon
@click="toggle"
>
<v-icon>mdi-record</v-icon>
</v-btn>
</v-item>
</v-item-group>
<v-btn
text
@click="next"
>
<v-icon>mdi-chevron-right</v-icon>
</v-btn>
</v-card-actions>
</v-card>
</template>
<script>
export default {
data: () => ({
length: 3,
onboarding: 0,
}),
methods: {
next () {
this.onboarding = this.onboarding + 1 === this.length
? 0
: this.onboarding + 1
},
prev () {
this.onboarding = this.onboarding - 1 < 0
? this.length - 1
: this.onboarding - 1
},
},
}
</script>
帐户创建
使用平滑动画创建表单。v-window
会自动跟踪当前的选择索引以自动改变过渡方向。 这可以通过 reverse
属性手动控制。
template script
<template>
<v-card
class="mx-auto"
max-width="500"
>
<v-card-title class="title font-weight-regular justify-space-between">
<span>{{ currentTitle }}</span>
<v-avatar
color="primary lighten-2"
class="subheading white--text"
size="24"
v-text="step"
></v-avatar>
</v-card-title>
<v-window v-model="step">
<v-window-item :value="1">
<v-card-text>
<v-text-field
label="Email"
value="john@vuetifyjs.com"
></v-text-field>
<span class="caption grey--text text--darken-1">
This is the email you will use to login to your Vuetify account
</span>
</v-card-text>
</v-window-item>
<v-window-item :value="2">
<v-card-text>
<v-text-field
label="Password"
type="password"
></v-text-field>
<v-text-field
label="Confirm Password"
type="password"
></v-text-field>
<span class="caption grey--text text--darken-1">
Please enter a password for your account
</span>
</v-card-text>
</v-window-item>
<v-window-item :value="3">
<div class="pa-4 text-center">
<v-img
class="mb-4"
contain
height="128"
src="https://cdn.vuetifyjs.com/images/logos/v.svg"
></v-img>
<h3 class="title font-weight-light mb-2">Welcome to Vuetify</h3>
<span class="caption grey--text">Thanks for signing up!</span>
</div>
</v-window-item>
</v-window>
<v-divider></v-divider>
<v-card-actions>
<v-btn
:disabled="step === 1"
text
@click="step--"
>
Back
</v-btn>
<v-spacer></v-spacer>
<v-btn
:disabled="step === 3"
color="primary"
depressed
@click="step++"
>
Next
</v-btn>
</v-card-actions>
</v-card>
</template>
<script>
export default {
data: () => ({
step: 1,
}),
computed: {
currentTitle () {
switch (this.step) {
case 1: return 'Sign-up'
case 2: return 'Create a password'
default: return 'Account created'
}
},
},
}
</script>